In the process of answering the following jQuery question Need help in Optimizing the below jquery code , I stumbled across another question about .find()
and .children()
.
The question was, given four selectboxes with ids state, city, branch, branchAddress, to remove all but the first option for each select boxes.
There has been several answers posted. Among those were :
$('#state,#city,#branch,#branchAddress').children('option:not(:first)').remove();
$('#state,#city,#branch,#branchAddress').children('option:not(:first-child)').remove();
$('#state,#city,#branch,#branchAddress').find('option:not(:first)').remove();
Solution 1 does not seem to work (removing all options, except the first option of the first select box) according to this js fiddle ( http://jsfiddle.net/QkNRf/1/ )
Solution 2 and 3 seem to work perfectly.
I would be glad if someone could point me what I missed, or explain to me why solution 3 works where solution 1 does not.