Reputation: 10872
I want to remove all options but the first from my <select/>
. I understand that children()
would not work recursively.
Is there any difference between
$('#mySelect :gt(0)').remove();
and
$('#mySelect').find(':gt(0)').remove();
?
Upvotes: 0
Views: 267
Reputation: 3051
find() method is useful if we already have parent element reference:
var parentElement = $('#mySelect');
/*
* there is some code..
* do some thing on parent
*/
Now if we want to get parentElement's children we can use either
parentElement.find('.xtz');
or $('.xtz',parentElement)
rather than using complete selector either
$('#mySelect .xtz');
or
$('#mySelect').find('.xtz');
Upvotes: 1
Reputation: 1074959
Shockingly I can't find a duplicate of this question, all the others are about speed.
There's no significant difference in the two lines of code you've quoted, no.
Upvotes: 3