And this could be used instead of document.getElementsByClassName :
swim = document.querySelectorAll('.swim');
<< NodeList [ <p.swim> ]
Note that this is not a live node list. See the section later in this chapter for more details
about live node lists.
CSS query selectors are a powerful way of specifying very precise items on a page. For
example, CSS pseudo-selectors can also be used to pinpoint a particular element. The fol-
lowing code, for example, will return only the last paragraph in the document:
run = document.querySelector('p:last-child');
All modern browsers support these methods and Internet Explorer supported it from ver-
sion 8 onwards. Version 8 of Internet Explorer only understands CSS2.1 selectors (what it
supports), so complex CSS3 notations such as x ~ y:empty will fail to work.
elements on a page using a CSS-style syntax. It uses docu-
ment.querySelectorAll() in the background whenever it can.
Search WWH ::