其他分享
首页 > 其他分享> > The HTML DOM (Document Object Model)

The HTML DOM (Document Object Model)

作者:互联网

原文链接:http://www.cnblogs.com/Linford-Xu/archive/2013/05/08/3066820.html

With the HTML DOM, JavaScript can access all the elements of an HTML  document.


The HTML DOM (Document Object Model)

When a web page is loaded, the browser creates a Document Object Model of the page.

The HTML DOM model is constructed as a tree of Objects

The HTML DOM Tree

DOM HTML tree

With a programmable object model, JavaScript gets all the power it needs to create  dynamic HTML:


Finding HTML Elements

Often, with JavaScript, you want to manipulate HTML elements.

To do so, you have to find the elements first. There are a couple of ways to do this:


Finding HTML Elements by Id

The easiest way to find HTML elements in the DOM, is by using the element id.

This example finds the element with id="intro":

Example

var x=document.getElementById("intro");


If the element is found, the method will return the element as an object (in  x).

If the element is not found, x will contain null.


Finding HTML Elements by Tag Name

This example finds the element with id="main", and then finds all <p> elements  inside "main":

Example

var x=document.getElementById("main"); var y=x.getElementsByTagName("p");

 Notice: Finding elements by class name does not work in Internet Explorer 5,6,7, and 8.

   

 

转载于:https://www.cnblogs.com/Linford-Xu/archive/2013/05/08/3066820.html

标签:elements,DOM,Object,HTML,Finding,Model,Document,JavaScript,page
来源: https://blog.csdn.net/weixin_30242907/article/details/97540468