Bug: Wrong selector-property and live with another context in jquery-nightly
hello,
i saw that you will add a new (and very nice) feature with jquery
1.3.3 (http://dev.jquery.com/changeset/6287). I found two bugs, that
should be fixed, to get this thing work properly:
1. the context-property is not taken into account in the closest-
operation:
you could add an optional parameter (default: document) to the closest-
method, that is used as a breaking contidion
for example.: while(cur && cur.ownerDocument && cur !=
parentOfContext). although this is a new feature for the closest-
method it could help fixing a bug in handling live/die handler, when
used with another context than the document.
here is a small testcase:
<!doctype html>
<html>
<head>
<script src="jquery-nightly.js"></script>
<style>
.invalid {
border: 1px solid #d00;
padding: 5px;
}
.listener {
border: 1px solid #000;
padding: 50px 0;
}
.valid {
border: 1px solid #0d0;
height: 200px;
}
</style>
<script>
$(function(){
$('div.box', $('div.listener')[0]).live('click', function(){
$('ul').append('<li>'+ this.className +'</li>');
});
});
</script>
</head>
<body>
<div class="box invalid">
<div class="listener">
<div class="box valid">
<div class="box valid">
</div>
</div>
</div>
</div>
<ul>
</ul>
</body>
</html>
2. wrong selector property in rare cases
if you run the following code on the jquery homepage $('a', $('#jq-
header, #jq-content'))
the selector property has the following value: #jq-header, #jq-content
a
here is a small testscript, wich you can run in firebug on the jquery
website:
var selectors = ["$('a', $('#jq-header'))", "$('a', $('#jq-header')
[0])", "$('a', $('#jq-header, #jq-content'))", "$('#jq-header').find
('a')", "$('#jq-header, #jq-content').find('a')", "$('a', $('#does-not-
exist'))"];
$.each([$('a', $('#jq-header')), $('a', $('#jq-header')[0]), $('a', $
('#jq-header, #jq-content')), $('#jq-header').find('a'), $('#jq-
header, #jq-content').find('a'), $('a', $('#does-not-exist'))],
function(i, jElements){
console.log('----------');
console.log('test case: '+ i);
console.log('select-operation: '+ selectors[i]);
console.log('selector property: '+ jElements.selector)
console.log('context property: '+ jElements.context)
console.log('found elements: '+ jElements.length);
console.log('----------');
});
regards
alex