<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>DPJ Online Blog &#187; Dojo</title>
	<atom:link href="http://blog.dpjonline.com/tag/dojo/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.dpjonline.com</link>
	<description>Computer Programming, Health, Science and Information Technology, Google Adsense, Online Business &#38; Adventure</description>
	<lastBuildDate>Tue, 10 Aug 2010 07:16:11 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>dojo.query: A CSS Query Engine For Dojo</title>
		<link>http://blog.dpjonline.com/2009/11/24/dojo-query-a-css-query-engine-for-dojo/</link>
		<comments>http://blog.dpjonline.com/2009/11/24/dojo-query-a-css-query-engine-for-dojo/#comments</comments>
		<pubDate>Tue, 24 Nov 2009 06:19:07 +0000</pubDate>
		<dc:creator>pRiMe</dc:creator>
				<category><![CDATA[IT Stuff]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Dojo]]></category>
		<category><![CDATA[dojo.query]]></category>
		<category><![CDATA[Javascript]]></category>

		<guid isPermaLink="false">http://blog.dpjonline.com/?p=181</guid>
		<description><![CDATA[dojo.query (returns dojo.NodeList) dojo.require(&#8220;dojo._base.query&#8221;); dojo.query() is the swiss army knife of DOM node manipulation in Dojo. Much like Prototype’s “$$” (bling-bling) function or JQuery’s “$” function, dojo.query provides robust, high-performance CSS-based node selector support with the option of scoping searches to a particular sub-tree of a document. Supported Selectors: dojo.query() supports a rich set of [...]]]></description>
			<content:encoded><![CDATA[<!-- AdSense Now! V1.83 -->
<!-- Post[count: 3] -->
<div class="adsense adsense-leadin" style="float:right;margin: 12px;"><script type="text/javascript"><!--
google_ad_client = "pub-7497154104883066";
/* 300x250, created 9/28/09 */
google_ad_slot = "1730150639";
google_ad_width = 300;
google_ad_height = 250;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div><div style="width:85%;">dojo.query (returns dojo.NodeList)<br />
dojo.require(&#8220;dojo._base.query&#8221;);</p>
<p>dojo.query() is the swiss army knife of DOM node manipulation in Dojo. Much like Prototype’s “$$” (bling-bling) function or JQuery’s “$” function, dojo.query provides robust, high-performance CSS-based node selector support with the option of scoping searches to a particular sub-tree of a document.<br />
Supported Selectors:</p>
<p>dojo.query() supports a rich set of CSS3 selectors, including:</p>
<ul>
<li>class selectors (e.g., .foo)</li>
<li>node type selectors like span</li>
<li>descendant selectors</li>
<li> &gt; child element selectors</li>
<li> #foo style ID selectors</li>
<li> * universal selector</li>
<li> ~, the immediately preceeded-by sibling selector</li>
<li> +, the preceeded-by sibling selector</li>
<li> attribute queries:
<ul>
<li>[foo] attribute presence selector</li>
<li> [foo='bar'] attribute value exact match</li>
<li> [foo~='bar'] attribute value list item match</li>
<li> [foo^='bar'] attribute start match</li>
<li> [foo$='bar'] attribute end match</li>
<li> [foo*='bar'] attribute substring match</li>
</ul>
</li>
<li> :first-child, :last-child, and : only-child positional selectors</li>
<li> :empty content emtpy selector</li>
<li> :checked pseudo selector</li>
<li> :nth-child(n), :nth-child(2n+1) style positional calculations</li>
<li> :nth-child(even), :nth-child(odd) positional selectors</li>
<li> :not(&#8230;) negation pseudo selectors</li>
</ul>
<p>Usage<br />
var foo: dojo.NodeList=dojo.query(query: String, root: String|DOMNode?, listCtor: Function?);</p>
<table border="0" width="90%">
<tbody>
<tr>
<th>parameter</th>
<th>type</th>
<th>description</th>
</tr>
<tr>
<td>query</td>
<td>String</td>
<td>The CSS3 expression to match against. For details on the syntax of CSS3 selectors, see</td>
</tr>
<tr>
<td>root</td>
<td>String|DOMNode	Optional.</td>
<td>A DOMNode (or node id) to scope the search from. Optional.</td>
</tr>
<tr>
<td>listCtor</td>
<td>Function</td>
<td>Optional.</td>
</tr>
</tbody>
</table>
<p><strong>Example 1</strong></p>
<p>search the entire document for elements with the class “foo”:</p>
<p>dojo.query(&#8220;.foo&#8221;);</p>
<p>these elements will match:</p>
<p><span class="foo"> </span><br />
<span class="foo bar"> </span></p>
<p class="thud foo">
<p><strong>Example 2</strong></p>
<p>search the entire document for elements with the classes “foo” and “bar”:</p>
<p>dojo.query(&#8220;.foo.bar&#8221;);</p>
<p>these elements will match:</p>
<p><span class="foo bar"> </span></p>
<p>while these will not:</p>
<p><span class="foo"> </span></p>
<p class="thud foo">
<p><strong>Example 3</strong></p>
<p>find elements which are descendants of paragraphs and which have a “highlighted” class:</p>
<p>dojo.query(&#8220;p span.highlighted&#8221;);</p>
<p>the innermost span in this fragment matches:</p>
<p class="foo"><span>&#8230;<br />
<span class="highlighted foo bar">&#8230;</span><br />
</span></p>
<p><strong>Example 4</strong></p>
<p>set an “odd” class on all odd table rows inside of the table #tabular_data, using the &gt; (direct child) selector to avoid affecting any nested tables:</p>
<p>dojo.query(&#8220;#tabular_data &gt; tbody &gt; tr:nth-child(odd)&#8221;).addClass(&#8220;odd&#8221;);</p>
<p><strong>Example 5</strong></p>
<p>remove all elements with the class “error” from the document and store them in a list:</p>
<p>var errors = dojo.query(&#8220;.error&#8221;).orphan();</p>
<p><strong>Example 6</strong></p>
<p>add an onclick handler to every submit button in the document which causes the form to be sent via Ajax instead:</p>
<p>dojo.query(&#8220;input[type='submit']&#8220;).onclick(function(e){<br />
dojo.stopEvent(e); // prevent sending the form<br />
var btn = e.target;<br />
dojo.xhrPost({<br />
form: btn.form,<br />
load: function(data){<br />
// replace the form with the response<br />
var div = dojo.doc.createElement(&#8220;div&#8221;);<br />
dojo.place(div, btn.form, &#8220;after&#8221;);<br />
div.innerHTML = data;<br />
dojo.style(btn.form, &#8220;display&#8221;, &#8220;none&#8221;);<br />
}<br />
});<br />
});</p>
<p><strong>Example 7</strong></p>
<p>Find every element in the page with the class &#8220;blueButton&#8221; assigned<br />
dojo.addOnLoad(function(){<br />
dojo.query(&#8220;.blueButton&#8221;).forEach(function(node, index, arr){<br />
console.debug(node.innerHTML);<br />
});<br />
});</p>
<p><strong>Simple Queries</strong></p>
<p>// all h3 elements<br />
dojo.query(&#8216;h3&#8242;)<br />
// all h3 elements which are first-child of their parent node<br />
dojo.query(&#8216;h3:first-child&#8217;)<br />
// a node with id=&#8221;main&#8221;<br />
dojo.query(&#8216;#main&#8217;)<br />
// all h3 elements within a node with id=&#8221;main&#8221;<br />
dojo.query(&#8216;#main h3&#8242;)<br />
// a &#8216;div&#8217; with an id=&#8221;main&#8221;<br />
dojo.query(&#8216;div#main&#8217;)<br />
// all h3 elements within a div with id=&#8221;main&#8221;<br />
dojo.query(&#8216;div#main h3&#8242;)<br />
// all h3 elements that are immediate children of a &#8216;div&#8217;, within node with id=&#8221;main&#8221;<br />
dojo.query(&#8216;#main div &gt; h3&#8242;)<br />
// all nodes with class=&#8221;foo&#8221;<br />
dojo.query(&#8216;.foo&#8217;)<br />
// all nodes with classes &#8220;foo&#8221; and &#8220;bar&#8221;<br />
dojo.query(&#8216;.foo.bar&#8217;)<br />
// all h3 elements that are immediate children of a node with id=&#8221;main&#8221;<br />
dojo.query(&#8216;#main &gt; h3&#8242;)</p>
<p><strong>Immediate Child Elements</strong></p>
<p>dojo.query(&#8216;#main &gt; *&#8217;)<br />
dojo.query(&#8216;#main &gt;&#8217;)<br />
dojo.query(&#8216;.foo &gt;&#8217;)<br />
dojo.query(&#8216;.foo &gt; *&#8217;)</p>
<p><strong>Queries rooted at a given element</strong></p>
<p>dojo.query(&#8216;&gt; *&#8217;, dojo.byId(&#8216;container&#8217;))<br />
dojo.query(&#8216;&gt; h3&#8242;, &#8216;main&#8217;)</p>
<p><strong>Compound queries<br />
Combining 2 or more selectors to produce one resultset</strong></p>
<p>dojo.query(&#8216;.foo, .bar&#8217;)</p>
<p><strong>Multiple class attribute values</strong></p>
<p>dojo.query(&#8216;.foo.bar&#8217;)</p>
<p><strong>Using attribute selectors</strong></p>
<p><strong>Picking out elements with particular attributes/values</strong></p>
<p>dojo.query(&#8216;[foo]&#8216;)<br />
dojo.query(&#8216;[foo$=\"thud\"]&#8216;)<br />
dojo.query(&#8216;[foo$=thud]&#8216;)<br />
dojo.query(&#8216;[foo$=\"thudish\"]&#8216;)<br />
dojo.query(&#8216;#main [foo$=thud]&#8216;)<br />
dojo.query(&#8216;#main [ title $= thud ]&#8216;)<br />
dojo.query(&#8216;#main span[ title $= thud ]&#8216;)<br />
dojo.query(&#8216;[foo|=\"bar\"]&#8216;)<br />
dojo.query(&#8216;[foo|=\"bar-baz\"]&#8216;)<br />
dojo.query(&#8216;[foo|=\"baz\"]&#8216;)<br />
dojo.query(&#8216;.foo:nth-child(2)&#8217;)</p>
<p><strong>Descendant selectors</strong></p>
<p>dojo.query(&#8216;&gt;&#8217;, &#8216;container&#8217;)<br />
dojo.query(&#8216;&gt; *&#8217;, &#8216;container&#8217;)<br />
dojo.query(&#8216;&gt; [qux]&#8216;, &#8216;container&#8217;)</p>
<p><strong>Sibling selectors</strong></p>
<p>dojo.query(&#8216;.foo + span&#8217;)<br />
dojo.query(&#8216;.foo ~ span&#8217;)<br />
dojo.query(&#8216;#foo ~ *&#8217;)<br />
dojo.query(&#8216;#foo ~&#8217;)</p>
<p><strong>Sub-selectors, using not()</strong></p>
<p>dojo.query(&#8216;#main span.foo:not(span:first-child)&#8217;)<br />
dojo.query(&#8216;#main span.foo:not(:first-child)&#8217;)</p>
<p><strong>Nth-child</strong></p>
<p>dojo.query(&#8216;#main &gt; h3:nth-child(odd)&#8217;)<br />
dojo.query(&#8216;#main h3:nth-child(odd)&#8217;)<br />
dojo.query(&#8216;#main h3:nth-child(2n+1)&#8217;)<br />
dojo.query(&#8216;#main h3:nth-child(even)&#8217;)<br />
dojo.query(&#8216;#main h3:nth-child(2n)&#8217;)<br />
dojo.query(&#8216;#main h3:nth-child(2n+3)&#8217;)<br />
dojo.query(&#8216;#main &gt; *:nth-child(2n-5)&#8217;)</p>
<p><strong>Using pseudo-selectors</strong></p>
<p>dojo.query(&#8216;#main2 &gt; :checked&#8217;)<br />
dojo.query(&#8216;#main2 &gt; input[type=checkbox]:checked&#8217;)<br />
dojo.query(&#8216;#main2 &gt; input[type=radio]:checked&#8217;)</p>
<p><strong>Count of checked checkboxes in a form with id myForm</strong><br />
dojo.query(&#8216;input:checked&#8217;, &#8216;myForm&#8217;).length
</div>
]]></content:encoded>
			<wfw:commentRss>http://blog.dpjonline.com/2009/11/24/dojo-query-a-css-query-engine-for-dojo/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>
