In association with heise online

02 July 2012, 09:56

W3C forges ahead with Selectors API

  • Twitter
  • Facebook
  • submit to slashdot
  • StumbleUpon
  • submit to reddit

W3C logo

The Web Applications Working Group at the W3C has published a last call working draft of the Selectors API Level 1 specification. Widely used in CSS, selectors are patterns that match a set of elements in a structure tree. As accessing elements in HTML documents using DOM methods such as getElementById or getElementsByTagName can quite laborious, frameworks like jQuery have developed simple CSS selector methods. Many browsers offer querySelector and querySelectorAll functions that also use these selectors.

The querySelector and querySelectorAll selectors allow DOM elements to be selected in a similar way to how they are selected in Cascading Style Sheets (CSS). For example, querySelectorAll('p.warning, p.error) will return all P elements that contain the "warning" or "error" class attribute. LI elements in an unordered list whose ID is "Navigation" can be returned using querySelectorAll('ul#Navigation>li'). Any issues can be raised until 19 July 2012, after which time the document will become a "recommendation" and will reach standard status.

The simultaneously released working draft of Level 2 of the Selectors API also contains the find, findall and matches methods. The first two functions search for the required elements in a set of DOM elements that is submitted as a parameter and return any elements they find. The matches method, on the other hand, only checks whether one of the scanned elements matches the selector.

(crve)

Print Version | Send by email | Permalink: http://h-online.com/-1629774
 


  • July's Community Calendar





The H Open

The H Security

The H Developer

The H Internet Toolkit