Reputation: 2088
Is there any benefit to the former over the latter, unless perhaps you were chaining a set of commands which meant that it was necessary to add an element mid way through the chain?
Upvotes: 0
Views: 56
Reputation: 3262
They have the same function. I think the difference is just the order, for manipulations. For example:
$('#one').css('background','red').add('#two').fadeOut();
And:
$('#one,#two').css('background','red').fadeOut();
The first example will set just the #one
with red text, then fade out both. The second example will set both with red text, then fade out both. You can set your own flux for effects and returns.
Upvotes: 1
Reputation: 57105
$('#one, #two')
is same as $('#one').add('#two')
When you a cached selector
var el = $('#one');
//you can do
el.add('#two');
// or
$('#two').add(el);
//Or
el.find('.el').add('#two');
Upvotes: 3