Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JQuery Remove Select Option From List

I have the following select box (I am not able to add a class or ID to the select form which is why I wrapped it in a div):

<div id="test"><select name="wpv-yr">
<option value="0" selected="selected">All Years</option>
<option value="2010">2010 (6)</option>
<option value="2011">2011 (12)</option>
<option value="2012">2012 (32)</option>
<option value="2013">2013 (129)</option>
<option value="2014">2014 (24)</option>
</select></div>

And I don't want to show the last option, 2014, in the drop down list. I've tried adding:

jQuery(document).ready(function() {
jQuery("div#test option[value=2014]").remove();
});

I've also tried single quotes around the value:

jQuery(document).ready(function() {
jQuery("div#test option[value='2014']").remove();
});

But that didn't work either. The 2014 option is still appearing in the list.

Where am I going wrong?

like image 987
gandjyar Avatar asked Nov 04 '13 15:11

gandjyar


1 Answers

I have just set up a fiddle here, and this works. Are you referencing the JQuery library in the page? The only change in my code is replacing jquery with $

$(document).ready(function () {
    $("div#test option[value=2014]").remove();
});
like image 136
Christian Phillips Avatar answered Oct 05 '22 11:10

Christian Phillips