If all the getXXX
methods available in the Dom utility are not enough to for us, the Selector Utility lets us locate nodes using CSS3 selectors. This is becoming increasingly popular as it doesn't require us to learn one more syntax such as that of XPath. We can use the same selectors used when declaring styles in a CSS stylesheet.
Just as for the Dom utility, you don't need to create an instance of Selector to use its methods, which either return an array of elements or a Boolean. Its methods are:
.query()
: Returns an array of elements based on a given selector. You can also specify a location to start the search, to reduce the time it takes to complete, and tell it that you want just the first one it finds..filter()
: Returns a selection of an array of nodes based on a further selection criteria..test()
: Returns true if the given node matches the selection criteria.
A single property is likely to be used in regular situations; document
lets you state the default document...