Document Object Model
Document Object Model
1. Document Object
2. Properties of document object
3. Methods of document object
4. Example of document object
1. window.document
Is same as
1. document
According to W3C - "The W3C Document Object Model (DOM) is a platform and
language-neutral interface that allows programs and scripts to dynamically access and
update the content, structure, and style of a document."
Method Description
writeln("string") writes the given string on the doucment with newline characte
getElementsByName() returns all the elements having the given name value.
getElementsByTagName() returns all the elements having the given tag name.
getElementsByClassName() returns all the elements having the given class name.
value is the property, that returns the value of the input text.
Let's see the simple example of document object that prints name with welcome
message.
1. <script type="text/javascript">
2. function printvalue(){
3. var name=document.form1.name.value;
4. alert("Welcome: "+name);
5. }
6. </script>
7.
8. <form name="form1">
9. Enter Name:<input type="text" name="name"/>
10. <input type="button" onclick="printvalue()" value="print name"/>
11. </form>
Enter Name: