Element#adjacent can select siblings childnodes and shouldn't
Reported by John-David Dalton | July 28th, 2008 @ 06:28 AM | in 1.6.1
Here is a test that shows that Element#adjacent can select siblings childnodes.
I have attached a patch to fix that.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/...">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Test</title>
<script src="prototype.js" type="text/javascript"></script>
<script type="text/javascript">
document.observe('dom:loaded', function() {
alert($('nyc').adjacent('li a'));
});
</script>
</head>
<body>
<ul id="cities">
<li class="us" id="nyc">New York</li>
<li class="uk" id="lon">London</li>
<li class="us" id="chi">Chicago</li>
<li class="jp" id="tok">Tokyo</li>
<li class="us" id="la">
<a href="http://www.google.com">Los Angeles</a>
</li>
<li class="us" id="aus">Austin</li>
</ul>
</body>
</html>
Comments and changes to this ticket
-
John-David Dalton July 28th, 2008 @ 06:29 AM
- → State changed from new to bug
-
John-David Dalton August 4th, 2008 @ 04:59 PM
I should make another version that uses Element#match instead :)
-

Jean-Philippe September 8th, 2008 @ 09:12 PM
Another way to patch this is:
adjacent: function() {
var args = $A(arguments), element = $(args.shift()), selector = args.shift(); return element.siblings().grep(new Selector(selector));},
See Kangax solution here : http://groups.google.com/group/p...
It's works fine and is soooo simple ! The magic of Selector#match method!
Jean-Philippe
-
John-David Dalton September 8th, 2008 @ 09:37 PM
@Jean Phillep - Element#adjacent allows an unlimited number of optional selectors
The method by kangax while very elegant doesn't account for that, I think it is meant as a quick fix.
-

Jean-Philippe September 10th, 2008 @ 07:25 PM
You're right, I didn't notice that. Kangax knew his solution was a quick fix, I didn't :D
Thanks.
Please Login or create a free account to add a new comment.
You can update this ticket by sending an email to from your email client. (help)
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
The Prototype JavaScript library.
