Is There Any Difference In Jquery("sel1").add("sel2") And Jquery("sel1, Sel2")
Well, the question is in the title. Is there any difference (performance, caveats) between multiple selector jQuery('selector1, selector2') and adding elements to selection with
Solution 1:
Yes, the first will create a jQuery object that contains elements matched by both selectors. The second will create an object that has elements matched by the first selector, then create and return a new object with both, without modifying the first object.
For example:
var jq1 = $('h1, h2'); // Will contain all <h1> and <h2> elements.
jq1.add('h3');
alert(jq1.filter('h3').length); // Will alert 0, because the // original object was not modified.
jq1 = jq1.add('h3');
alert(jq1.filter('h3').length); // Will alert the number of <h3> elements.
Post a Comment for "Is There Any Difference In Jquery("sel1").add("sel2") And Jquery("sel1, Sel2")"