tags:

views:

130

answers:

6

why DOM is required for javascript ...how exactly javascript works......I am new to this plz help

Thanks

+3  A: 

An html page can be represented as a tree ; the DOM is the specification for this tree.

Javascript implementations are able to work this tree : add/remove/modify nodes. A good documentation about that is the one made by Mozilla : https://developer.mozilla.org/en/dom

Guillaume Lebourgeois
A: 

JavaScript is a programming language.

DOM is an API that describes objects and methods that you can use to manipulate a document.

A number of programming language implement DOM so that you can manipulate XML/HTML/etc documents using said language. JavaScript is one of them.

Using DOM saves every language development team from having to design their own set of objects and methods to manipulate documents, and saves users of those languages from having to learn a new set of objects and methods whenever they switch languages.

David Dorward
A: 

The DOM is not required for Javascript, the DOM is a representation of the HTML page being manipulated that is accessible from Javascript. If you don't want to do anything with the HTML page then you don't need to touch the DOM.

How Javascript works is a much bigger question and beyond the scope of an answer here, suffice it to say that Javascript is an interpreted scripting language based on the standards-based ECMAScript.

Lazarus
A: 

You need to look at sites such as: http://www.w3schools.com/js/default.asp. That should give you enough info.

Any questions after that can be posted back here.

Simon
+3  A: 

While JavaScript is the programming language which will allow you to operate on the DOM objects and to manipulate them programmatically, the DOM will provide you with methods and properties to retrieve, modify, update, and delete parts of the document you are working on. For example, you may retrieve the value of an HTML text input control as a string using the DOM. You could then use the JavaScript "+" operator to concatenate that string with another one in order to make a meaningful sentence. You would then use the DOM "alert()" method to display the string in a dialog to the user. See also the examples below.

If a Web page were a piece of imported Swedish furniture, the DOM would be the illustrations of the parts - the shelves, bolts, Allen wrenches and screwdrivers. It's possible to write instructions on how to put the parts together and use the parts in any number of languages, but you'll only use the ones written in the one you understand. The manual makes it easy to put the furniture together by using written instructions (JavaScript) to reference illustrations of objects (DOM) which represent actual objects (browser's rendering engine). (Thanks to Jonathan for the analogy!)

What's this "language-neutral" hype with the DOM? Why is the DOM language-neutral if the only language ever used to access it is JavaScript? Well, that is not quite correct. For example, Mozilla uses the DOM internally both in C++ and JavaScript for its user interface. The editor, for instance, uses the DOM extensively in order to insert, modify, and delete the HTML that you are seeing when you compose a page in the Composer module. Other known implementations of the DOM include Perl, Java, ActiveX, Python, and probably others. This is of course only possible thanks to the language-neutrality of the DOM.

More details check HERE and Wiki.

Incognito
A: 

Javascript is a programming language that is classified as object based language. Commonly javascript engines are embedded in browsers and major field of operation is document object model that is representational structure of HTML/XML document loaded in the the browser.

Browser and DOM is not required as dependencies for javascript execution. But they provide a dominant execution environment. Javascript code that is not manipulating DOM needs DOM event model to be triggered at-least.

Shoaib