<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	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/"
		>
<channel>
	<title>Comments on: JavaScript and Selectors</title>
	<atom:link href="http://web-graphics.com/2006/05/12/javascript-and-selectors/feed/" rel="self" type="application/rss+xml" />
	<link>http://web-graphics.com/2006/05/12/javascript-and-selectors/</link>
	<description>Web development concerns, usually revolving around implimentation of designs into graphics, CSS, and HTML.</description>
	<lastBuildDate>Sat, 27 Feb 2010 12:10:47 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Meredith Borstadt</title>
		<link>http://web-graphics.com/2006/05/12/javascript-and-selectors/comment-page-1/#comment-54265</link>
		<dc:creator>Meredith Borstadt</dc:creator>
		<pubDate>Wed, 03 Feb 2010 04:50:56 +0000</pubDate>
		<guid isPermaLink="false">http://web-graphics.com/2006/05/12/javascript-and-selectors/#comment-54265</guid>
		<description>Excellent blog. You have brought in a new devotee. Please maintain the great writings and I look forward to more of your newsworthy updates.</description>
		<content:encoded><![CDATA[<p>Excellent blog. You have brought in a new devotee. Please maintain the great writings and I look forward to more of your newsworthy updates.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ann  Birret</title>
		<link>http://web-graphics.com/2006/05/12/javascript-and-selectors/comment-page-1/#comment-14123</link>
		<dc:creator>Ann  Birret</dc:creator>
		<pubDate>Fri, 15 Jun 2007 13:09:57 +0000</pubDate>
		<guid isPermaLink="false">http://web-graphics.com/2006/05/12/javascript-and-selectors/#comment-14123</guid>
		<description>Thanks for this really interesting post. It appears really helpful for me. I would like to ask you if I could translate it and include it in our page, also with link to your page. Alternatively I would like to put link to your page on my section with interesting articles. If it would be possible to put this link on my page please email me. One more time thanks for really great article. Greetings</description>
		<content:encoded><![CDATA[<p>Thanks for this really interesting post. It appears really helpful for me. I would like to ask you if I could translate it and include it in our page, also with link to your page. Alternatively I would like to put link to your page on my section with interesting articles. If it would be possible to put this link on my page please email me. One more time thanks for really great article. Greetings</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Lee, ChihCheng</title>
		<link>http://web-graphics.com/2006/05/12/javascript-and-selectors/comment-page-1/#comment-773</link>
		<dc:creator>Lee, ChihCheng</dc:creator>
		<pubDate>Sat, 02 Sep 2006 17:03:52 +0000</pubDate>
		<guid isPermaLink="false">http://web-graphics.com/2006/05/12/javascript-and-selectors/#comment-773</guid>
		<description>Bug report:

If use UTF-8 charset, the tooltips will die.

for example, search the: BubbleTooltips.html  file, and change:

charset=iso-8859-1  -&gt;  utf-8

then , the ToolTips will not work.</description>
		<content:encoded><![CDATA[<p>Bug report:</p>
<p>If use UTF-8 charset, the tooltips will die.</p>
<p>for example, search the: BubbleTooltips.html  file, and change:</p>
<p>charset=iso-8859-1  -&gt;  utf-8</p>
<p>then , the ToolTips will not work.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: liorean</title>
		<link>http://web-graphics.com/2006/05/12/javascript-and-selectors/comment-page-1/#comment-351</link>
		<dc:creator>liorean</dc:creator>
		<pubDate>Tue, 27 Jun 2006 21:05:26 +0000</pubDate>
		<guid isPermaLink="false">http://web-graphics.com/2006/05/12/javascript-and-selectors/#comment-351</guid>
		<description>&lt;p&gt;Jeff: XPath potential algorithmical complexity is higher than selectors. Selectors matching can always be done unidirectionally, which is not true for XPath. So, selectors can be optimised harder than XPath. XPath has a worst case algorithmical complexity of O(&lt;var&gt;n&lt;/var&gt;&lt;sup&gt;&lt;var&gt;x&lt;/var&gt;&lt;/sup&gt;) for any value of &lt;var&gt;x&lt;/var&gt;. I&#039;m not sure what the worts case algorithmical complexity of selectors might be, but given what I know about &lt;code&gt;NodeList&lt;/code&gt; traversal, I&#039;d say O(&lt;var&gt;n&lt;/var&gt;&lt;sup&gt;2&lt;/sup&gt;) sounds likely.&lt;/p&gt;
&lt;p&gt;If you want to find elements matching a group of selectors in a given document: You can always go from the root, testing the first sequence of selectors in each selector towards the document root element and queue up testing that sequence of simple selectors against all elements in it&#039;s subtree. In case of a match, queue up testing the next sequence of simple selectors on the subtree of the matching element, excluding elements dependent on what combinator was used. This way, the traversal doesn&#039;t have to visit any node more than once. If the last sequence of simple selectors in one of the selectors matched, then the matching element is added to the list that is to be returned.&lt;/p&gt;
&lt;p&gt;If you want to find out whether a given element matches a certain group of selectors, you do it the opposite way. You test the element against the last sequence of simple selectors, and then you traverse backwards, towards the root, testing elements dependent on what combinator was used, until you&#039;ve either run out of elements to test or you have found a match to the first sequence of simple selectors. If you have found a match, you abort the traversal and return &lt;code&gt;true&lt;/code&gt;. If you have run out of elements to test, you return &lt;code&gt;false&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;When I said that you only have to visit any given node once, I didn&#039;t take certain pseudo class, pseudo element or negation simple selectors into account. Either the testing for these can be done traversing backwards on each node, or it can be moved from the simple selectors testing into the traversal subtree exclusion by the code generator.&lt;/p&gt;</description>
		<content:encoded><![CDATA[<p>Jeff: XPath potential algorithmical complexity is higher than selectors. Selectors matching can always be done unidirectionally, which is not true for XPath. So, selectors can be optimised harder than XPath. XPath has a worst case algorithmical complexity of O(<var>n</var><sup><var>x</var></sup>) for any value of <var>x</var>. I&#8217;m not sure what the worts case algorithmical complexity of selectors might be, but given what I know about <code>NodeList</code> traversal, I&#8217;d say O(<var>n</var><sup>2</sup>) sounds likely.</p>
<p>If you want to find elements matching a group of selectors in a given document: You can always go from the root, testing the first sequence of selectors in each selector towards the document root element and queue up testing that sequence of simple selectors against all elements in it&#8217;s subtree. In case of a match, queue up testing the next sequence of simple selectors on the subtree of the matching element, excluding elements dependent on what combinator was used. This way, the traversal doesn&#8217;t have to visit any node more than once. If the last sequence of simple selectors in one of the selectors matched, then the matching element is added to the list that is to be returned.</p>
<p>If you want to find out whether a given element matches a certain group of selectors, you do it the opposite way. You test the element against the last sequence of simple selectors, and then you traverse backwards, towards the root, testing elements dependent on what combinator was used, until you&#8217;ve either run out of elements to test or you have found a match to the first sequence of simple selectors. If you have found a match, you abort the traversal and return <code>true</code>. If you have run out of elements to test, you return <code>false</code>.</p>
<p>When I said that you only have to visit any given node once, I didn&#8217;t take certain pseudo class, pseudo element or negation simple selectors into account. Either the testing for these can be done traversing backwards on each node, or it can be moved from the simple selectors testing into the traversal subtree exclusion by the code generator.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: hax</title>
		<link>http://web-graphics.com/2006/05/12/javascript-and-selectors/comment-page-1/#comment-326</link>
		<dc:creator>hax</dc:creator>
		<pubDate>Tue, 20 Jun 2006 06:02:33 +0000</pubDate>
		<guid isPermaLink="false">http://web-graphics.com/2006/05/12/javascript-and-selectors/#comment-326</guid>
		<description>XPath doesn&#039;t have pseudo-class and pseudo-element, and the syntax of CSS selectors is refined so it is more straightforward to write and understand. Of couse there are sth XPath can do but CSS selector not, eg. query a parent node as the pattern of descendants.</description>
		<content:encoded><![CDATA[<p>XPath doesn&#8217;t have pseudo-class and pseudo-element, and the syntax of CSS selectors is refined so it is more straightforward to write and understand. Of couse there are sth XPath can do but CSS selector not, eg. query a parent node as the pattern of descendants.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jeff Schiller</title>
		<link>http://web-graphics.com/2006/05/12/javascript-and-selectors/comment-page-1/#comment-306</link>
		<dc:creator>Jeff Schiller</dc:creator>
		<pubDate>Fri, 16 Jun 2006 17:43:08 +0000</pubDate>
		<guid isPermaLink="false">http://web-graphics.com/2006/05/12/javascript-and-selectors/#comment-306</guid>
		<description>Out of curiosity, assuming XML nodes, is there anything that can be done using CSS Selectors that cannot be done with an equivalent XPath expression?

Also, I&#039;m not sure why you believe XPath would be slower, maybe I don&#039;t know enough about browser internals though...</description>
		<content:encoded><![CDATA[<p>Out of curiosity, assuming XML nodes, is there anything that can be done using CSS Selectors that cannot be done with an equivalent XPath expression?</p>
<p>Also, I&#8217;m not sure why you believe XPath would be slower, maybe I don&#8217;t know enough about browser internals though&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dustin Diaz</title>
		<link>http://web-graphics.com/2006/05/12/javascript-and-selectors/comment-page-1/#comment-298</link>
		<dc:creator>Dustin Diaz</dc:creator>
		<pubDate>Thu, 15 Jun 2006 16:21:20 +0000</pubDate>
		<guid isPermaLink="false">http://web-graphics.com/2006/05/12/javascript-and-selectors/#comment-298</guid>
		<description>I don&#039;t have much to say except for the fact that having selector support would just be way cool for JavaScript. Having seen the growing number of cases of people wanting &quot;getElementsBySelector&quot; and $$(selector) and...well the list goes on; it would be down right logical to just implement a feature like that within the language.</description>
		<content:encoded><![CDATA[<p>I don&#8217;t have much to say except for the fact that having selector support would just be way cool for JavaScript. Having seen the growing number of cases of people wanting &#8220;getElementsBySelector&#8221; and $$(selector) and&#8230;well the list goes on; it would be down right logical to just implement a feature like that within the language.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mike McNally</title>
		<link>http://web-graphics.com/2006/05/12/javascript-and-selectors/comment-page-1/#comment-179</link>
		<dc:creator>Mike McNally</dc:creator>
		<pubDate>Mon, 15 May 2006 21:08:49 +0000</pubDate>
		<guid isPermaLink="false">http://web-graphics.com/2006/05/12/javascript-and-selectors/#comment-179</guid>
		<description>I don&#039;t think there&#039;s much of a performance issue with selectors used for event listening, at least for events driven by mouse and keyboard happenings.  The only time the set of listening nodes is interesting is the point at which an event actually happens. Currently the browser can determine whether a node it&#039;s visiting has a handler by simply checking a pointer.  With selector-based registration, the browser would additionally need to match the nodes against the set of registered selectors. That doesn&#039;t seem so bad, as for any given page the number of such selectors shouldn&#039;t be that great, and the node vs. selector predicate would have to be fast anyway. It&#039;s not as if the browser has to check all the nodes on a page, because it knows already exactly what nodes to check for the event.

As to the idea of selectors being implemented as native Javascript language elements, I don&#039;t see what good that&#039;d do as there are no other language elements against which a selector makes sense. In general Javascript does execute in the context of a DOM, but those elements are themselves not part of the language spec per se.  Thus it seems to me that definining the semantics for selectors requires references to things (like the way a node&#039;s parent is found) that are not part of the language per se, which seems pretty weird for a language element.</description>
		<content:encoded><![CDATA[<p>I don&#8217;t think there&#8217;s much of a performance issue with selectors used for event listening, at least for events driven by mouse and keyboard happenings.  The only time the set of listening nodes is interesting is the point at which an event actually happens. Currently the browser can determine whether a node it&#8217;s visiting has a handler by simply checking a pointer.  With selector-based registration, the browser would additionally need to match the nodes against the set of registered selectors. That doesn&#8217;t seem so bad, as for any given page the number of such selectors shouldn&#8217;t be that great, and the node vs. selector predicate would have to be fast anyway. It&#8217;s not as if the browser has to check all the nodes on a page, because it knows already exactly what nodes to check for the event.</p>
<p>As to the idea of selectors being implemented as native Javascript language elements, I don&#8217;t see what good that&#8217;d do as there are no other language elements against which a selector makes sense. In general Javascript does execute in the context of a DOM, but those elements are themselves not part of the language spec per se.  Thus it seems to me that definining the semantics for selectors requires references to things (like the way a node&#8217;s parent is found) that are not part of the language per se, which seems pretty weird for a language element.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Patrick Corcoran</title>
		<link>http://web-graphics.com/2006/05/12/javascript-and-selectors/comment-page-1/#comment-178</link>
		<dc:creator>Patrick Corcoran</dc:creator>
		<pubDate>Mon, 15 May 2006 17:45:08 +0000</pubDate>
		<guid isPermaLink="false">http://web-graphics.com/2006/05/12/javascript-and-selectors/#comment-178</guid>
		<description>I agree that the current state of affairs with regard to DOM manipulation is wanting.

But I don&#039;t really see the need to solve this problem by adding new layers of syntax and language extensions.  That to me is overkill.  If every problem were solved thus, JavaScript would ultimately end up as a worse syntactical mess than perl.  (With all due respect to perl... :)

The API needed to solve this problem is in my opinion a wrapper of utility classes.  Create a DOMSelector object, write an interpreted library for it that works across all browsers today, and then let the browser manufacturers internalize and optimize that in native code, all voluntarily and in good time.

I guess I just don&#039;t see the need to constantly formalize language extensions just to simplify the code of common design patterns.</description>
		<content:encoded><![CDATA[<p>I agree that the current state of affairs with regard to DOM manipulation is wanting.</p>
<p>But I don&#8217;t really see the need to solve this problem by adding new layers of syntax and language extensions.  That to me is overkill.  If every problem were solved thus, JavaScript would ultimately end up as a worse syntactical mess than perl.  (With all due respect to perl&#8230; :)</p>
<p>The API needed to solve this problem is in my opinion a wrapper of utility classes.  Create a DOMSelector object, write an interpreted library for it that works across all browsers today, and then let the browser manufacturers internalize and optimize that in native code, all voluntarily and in good time.</p>
<p>I guess I just don&#8217;t see the need to constantly formalize language extensions just to simplify the code of common design patterns.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Erik Arvidsson</title>
		<link>http://web-graphics.com/2006/05/12/javascript-and-selectors/comment-page-1/#comment-177</link>
		<dc:creator>Erik Arvidsson</dc:creator>
		<pubDate>Mon, 15 May 2006 17:08:28 +0000</pubDate>
		<guid isPermaLink="false">http://web-graphics.com/2006/05/12/javascript-and-selectors/#comment-177</guid>
		<description>Very good points indeed.

There is a huge need for testing if a node matches a selector. I think releasing a spec without that would be a huge oversight.

What about relative expressions? In CSS Selectors everything is relative to the document. For example how would we use this to get all the children elements of an element?

I think we could generalize the event attachment case even more. We could have an object that gets called whenever a node is inserted, modified or removed which causes a match. Basically, during the style resolution, we do callbacks to a javascript object.

var sel = new Selector(&#039;.foo&#039;);    
sel.addEventListener(&#039;match&#039;, f, true); // or non EventTarget interface    
sel.addEventListener(&#039;unmatch&#039;, g, true);    
sel.watchMatch(document);    

where the relatedTarget would be the node that started to match. This would require that the item keeps track of matching nodes, which like you said, I doubt that browsers do. However, letting the browser do this for us might save some time and make this less buggy/more efficient... and this case is simpler because the selector text is known. It would still be useful if we only had &#039;match&#039; but then all apps would have to duplicate all this code over and over and over.</description>
		<content:encoded><![CDATA[<p>Very good points indeed.</p>
<p>There is a huge need for testing if a node matches a selector. I think releasing a spec without that would be a huge oversight.</p>
<p>What about relative expressions? In CSS Selectors everything is relative to the document. For example how would we use this to get all the children elements of an element?</p>
<p>I think we could generalize the event attachment case even more. We could have an object that gets called whenever a node is inserted, modified or removed which causes a match. Basically, during the style resolution, we do callbacks to a javascript object.</p>
<p>var sel = new Selector(&#8216;.foo&#8217;);<br />
sel.addEventListener(&#8216;match&#8217;, f, true); // or non EventTarget interface<br />
sel.addEventListener(&#8216;unmatch&#8217;, g, true);<br />
sel.watchMatch(document);    </p>
<p>where the relatedTarget would be the node that started to match. This would require that the item keeps track of matching nodes, which like you said, I doubt that browsers do. However, letting the browser do this for us might save some time and make this less buggy/more efficient&#8230; and this case is simpler because the selector text is known. It would still be useful if we only had &#8216;match&#8217; but then all apps would have to duplicate all this code over and over and over.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
