- The Book of Dojo
- Quick Installation
- Hello World
- Debugging Tutorial
- Introduction
- Part 1: Life With Dojo
- Part 2: Dijit
- Part 3: JavaScript With Dojo and Dijit
- Part 4: Testing, Tuning and Debugging
- Part 5: DojoX
- The Dojo Book, 0.4
Relative Position Query
Submitted by criecke on Tue, 06/05/2007 - 19:53.
An optional second parameter to dojo.query indicates the root node for searching. If a string is passed, dojo.query() assumes it to be the ID of the element to use as the search root, otherwise it will expect a DOM node. In all of our examples so far, the second parameter has been left out, and defaults to document, the root of the HTML page. (Actually, it's dojo.doc, which is "document", but can be modified with dojo.withDocument).
The following shows how the second parameter affects the result:
<html>
<head>
<script type="text/javascript" src="../js/dojo/dojo.js"></script>
<script type="text/javascript">
dojo.addOnLoad(function() {
console.debug(dojo.query("button").length); // Outputs "3"
console.debug(dojo.query("button", "thisForm").length); // outputs 1
});
</script>
</head>
<body>
<button id="b1" />
<button id="b2" />
<form id="thisForm" >
<button id="formB" />
</form>
</body>
</html>
<head>
<script type="text/javascript" src="../js/dojo/dojo.js"></script>
<script type="text/javascript">
dojo.addOnLoad(function() {
console.debug(dojo.query("button").length); // Outputs "3"
console.debug(dojo.query("button", "thisForm").length); // outputs 1
});
</script>
</head>
<body>
<button id="b1" />
<button id="b2" />
<form id="thisForm" >
<button id="formB" />
</form>
</body>
</html>
- Printer-friendly version
- Login or register to post comments
- Unsubscribe post
This example doesn't work
This example doesn't work for my Firefox 2.0.0.11, it only shows the first button and outputs on console '1' and '0', but works on IE7.
This version worked on my Firefox's version.