Java Reference
In-Depth Information
Each of these objects inherits all the properties and methods of the Node object, but also has some
properties and methods of its own. You look at some examples in the next section.
dom objects and their properties and methods
If you tried to look at the properties and methods of all the objects in the DOM, it would take up
half the topic. Instead you're going to actively consider only three of the objects, namely the Node
object, the Element object, and the Document object. This is all you'll need to be able to create,
amend, and navigate your tree structure. Also, you're not going to spend ages trawling through
each of the properties and methods of these objects, but rather look only at some of the most useful
properties and methods and use them to achieve specific ends.
Note Appendix C contains a relatively complete reference to the DOM, its
objects, and their properties.
the Document Object and its Methods
The Document reference type exposes various properties and methods that are very helpful to
someone scripting the DOM. Its methods enable you to find individual or groups of elements and
create new elements, attributes, and text nodes. Any DOM scripter should know these methods and
properties, because they're used quite frequently.
The Document object's methods are probably the most important methods you'll learn. Although
many tools are at your disposal, the Document object's methods let you find, create, and delete
elements in your page.
Finding Elements or an Element
Let's say you have an HTML web page—how do you go about getting back a particular element
on the page in script? The Document reference type exposes the following methods to perform this
task.
methods of the doCument objeCt
desCription
Returns a reference (a node) of an element, when supplied
with the value of the id attribute of that element
getElementById(idValue)
Returns a reference (a node list) to a set of elements
that have the same tag as the one supplied in the
argument
getElementsByTagName(tagName)
Returns a reference (a node) of the first element that
matches the given CSS selector
querySelector(cssSelector)
Returns a reference (a node list) to a set of elements that
match the given CSS selector
querySelectorAll(cssSelector)
 
Search WWH ::




Custom Search