An even more subtle bug in the original version is that multiple copies of the same node may appear in the result array. For example, the selector '.foo .bar .mumble', when applied to the following tree:
...produces two copies of the mumble node, because it finds it by following two different paths. By contrast, my implementation visits each node in the entire document tree exactly once, so it is guaranteed to produce either 0 or 1 copy of each node in the result array.<div class="foo">
<div class="bar">
<div class="bar">
<div class="mumble">mumble</div>
</div>
</div>
</div>
7 comments:
"this results in finding the outermost node in the entire document whose ID matches, even if searching a subtree. Since ID's are not guaranteed to be unique, this can produce the wrong node."
Are you kidding??
Speaking of the "id" attribute, W3C has this to say: "This attribute assigns a name to an element. This name must be unique in a document."
(See the spec)
This functionality is further underscored by the fact that there is no "node.getElementById()" method available, it always must be used as "document.getElementById()".
The purpose of "id" is to assign a unique identity to an element. If you don't want uniqueness, that's what "class" is for.
The bottom line is that IDs are guaranteed to be unique, unless you make a practice of breaking the rules of valid XHTML. If you run into a case where getElementsBySelector() catches the wrong element by ID, then the proper place to fix the problem is to make sure all of your ID attributes are uniquely-named, not in fixing the "bug" which pointed out your error.
Don't fix what isn't broken. If anything, your changes to this function simply make is easier for people to ignore the standards which have made the web relatively simple to code for in recent years. That's not good!
-www.kramers.ws
I am happy reading your blog, I gained a piece of knowledge. Kindly continue the work.
Spoken English Classes in Chennai
Spoken English in Chennai
Top 10 Spoken English Classes in Chennai
Best IELTS Coaching in Chennai
IELTS Coaching Centre in Chennai
English Classes in Mumbai
English Speaking Classes in Mumbai
Best IELTS Coaching in Mumbai
IELTS Coaching in Mumbai
Spoken English Class in Anna Nagar
Thanks for sharing the great information. Car Service Bentleigh | Mechanic Hughesdale
Fullforms
Fullforms
Fullforms
Fullforms
Fullforms
Fullforms
Fullforms
Fullforms
There may be noticeably a bundle to know about this. I assume you made certain good factors in options also. 바카라
Carlton Driving School
Ringwood Driving School
bundoora Driving School
Post a Comment