Login Register

Selecting Nodes by Tag, ID or Class

The most popular methods for selecting nodes are by tag name, or the class and id attributes of the tag. Those are the most popular selectors for CSS files too. So, as you'd expect, dojo.query makes these easy:

// Query by tag.  Equivalent to DOM document.getElementsByTagName("IMG");
console.dir(dojo.query("img"));   // Non-case sensitive, so IMG would work too.
// Query by class.  Equivalent to big loop on previous page
console.dir(dojo.query(".offToSeeTheWij"));   
// Query by id.  Equivalent to DOM document.getElementById("widget123");
// or dojo.byId("widget123")
console.dir(dojo.query("#widget123"));

As with CSS, you can combine selectors in dojo.query to create Compound Selectors. By smooshing the selectors "a" and "b" against each other, you say "select nodes that have both properties a and b", as in:

// Select just image tags with the class offToSeeTheWij
console.dir(dojo.query("img.offToSeeTheWij"));