官术网_书友最值得收藏!

Understanding the DOM

One of the most powerful aspects of jQuery is its ability to make selecting elements in the DOM easy. The DOM serves as the interface between JavaScript and a web page; it provides a representation of the source HTML as a network of objects rather than as plain text.

This network takes the form of a family tree of elements on the page. When we refer to the relationships that elements have with one another, we use the same terminology that we use when referring to family relationships: parents, children, and so on. A simple example can help us understand how the family tree metaphor applies to a document:

<html>
  <head>
    <title>the title</title>
  </head>
  <body>
    <div>
      <p>This is a paragraph.</p>
      <p>This is another paragraph.</p>
      <p>This is yet another paragraph.</p>
    </div>
  </body>
</html>

Here, <html> is the ancestor of all the other elements; in other words, all the other elements are descendants of <html>. The <head> and <body> elements are not only descendants, but children of <html> as well. Likewise, in addition to being the ancestor of <head> and <body>, <html> is also their parent. The <p> elements are children (and descendants) of <div>, descendants of <body> and <html>, and siblings of each other.

To help visualize the family tree structure of the DOM, we can use a number of software tools, such as the Firebug plugin for Firefox or the Web Inspector in Safari or Chrome.

With this tree of elements at our disposal, we'll be able to use jQuery to efficiently locate any set of elements on the page. Our tools to achieve this are jQuery selectors and traversal methods.

主站蜘蛛池模板: 海伦市| 伊宁市| 灌南县| 武强县| 连州市| 涞源县| 新安县| 湟中县| 临江市| 烟台市| 潞西市| 杭锦后旗| 息烽县| 东丰县| 南安市| 芒康县| 元氏县| 九龙城区| 和林格尔县| 湘潭县| 微山县| 旌德县| 新沂市| 襄垣县| 卓资县| 芜湖市| 宽甸| 靖边县| 崇信县| 益阳市| 平江县| 满洲里市| 阿瓦提县| 泸水县| 台前县| 香格里拉县| 什邡市| 北安市| 陇南市| 白城市| 双峰县|