In the process of answering the next jQuery question I need help optimizing below the jquery code , I came across another question about .find() and .children() .
The question was that for four mailboxes with identifiers, state , city , branch , branchAddress , to remove everything except the first option for each selection window.
Several responses have been posted. Among them 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 (deleting all parameters except the first option of the first selection window) according to this js script ( http://jsfiddle.net/QkNRf/1/ )
Solution 2 and 3 seem to work fine.
I would be happy if someone could tell me what I missed, or explain to me why solution 3 works where solution 1 does not.
source share