So I have made the following fiddle:
Code:
$(document).ready(function(){
var html = '<div><div class="c">1</div><div class="c">2</div></div>';
//approach 1
var $html = $(html);
var $elts = (".c", $html);
console.log($elts.length);
//approach 2
$elts = $(".c", $(html));
console.log($elts.length);
});
Output:
1
2
Why do these two approaches differ?
EDIT:
This is JQuery 1.10.1 by the way.
(".c", $html);?$in front of the parenthesis, it's not a jQuery object. Only the$htmlinside is a jQuery object, the rest is ignored. You could have("foo", $html);and still get a result of 1.("comma operator claims another victim", $html)