The DOM model and Javascript
The Document Object Model (or DOM model for short) is used to identify the various objects or elements in a web page and how they are related to the web page itself. The DOM model is used to interact with objects and elements on a webpage when developing it and is used by virtually all popular web programming languages which comprises of XML and HTML among others.
The DOM model can be accessed and used based on language specific syntax, i.e. referring to the DOM model in HTML differs from referring to it in PHP. The DOM model also has prewritten libraries to comprehensively interact with different aspects of a web page. The DOM model is also widely used in developing Javascript code and was in fact partly created for interactivity with web pages using Javascript. Several versions of the DOM were created to enhance functionality namely the Legacy DOM (first developed to be used with Javascript) and the intermediate DOM, it was later standardized to a common syntax to work on all standard browsers by the World Wide Web consortium.
The DOM model is used to get or set values to different visual aspects on a web page in Javascript. Here are some basic syntax used to represent certain parts of your interface using DOM in Javascript:
- Screen.height - returns the height of the user's screen in pixels.
- URL - returns or sets the complete URL of the web page that the code is executed on.
- Title - returns or sets the title of the website that the code exists on.
- Button - Returns a value which represents a mouse button pressed. (i.e. 1 = left, 2 = right)
- Scrollwidth - Used to return a width of any object on a page or the page itself.
- Implementation - Returns the DOM syntax implemented in the page it is executed on.
There are several other methods and properties used to represent parts of a webpage. Javascript is the only language that is entirely dependant on the DOM to function. HTML, Perl and other languages can be written utilizing the DOM but pages can still be displayed without rendering the DOM part of the HTML code, this is not true with Javascript. Thus the DOM is an integral part of Javascript.