ios85
ios85

Reputation: 2134

Remove Select option from Drop Down with jQuery

I am having a problem removing an option from my drop down list. It does nothing when I load the page any ideas? I am using .remove() but this is doing nothing.

<!DOCTYPE html>
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<title>Test</title>
<script>
$(document).ready(function () {
$("#bytype option[value='foo']").remove();  
});
</script>
</head>
<body>

<select name="bytype" id="bytype">
<option value="foo">foo</option>
<option value="Boo">Boo</option>
<option value="Coo">Coo</option>                               
</select> 

</body>
</html>

Upvotes: 1

Views: 1470

Answers (4)

petschekr
petschekr

Reputation: 1311

Use this instead. Replace 'Your value' with the value of foo.

$("#Select ID").removeOption("Your Value");

Upvotes: 1

mbx-mbx
mbx-mbx

Reputation: 1775

You have a typo in your selector bytpe should be bytype

Upvotes: 0

Brandon
Brandon

Reputation: 69973

$("#bytpe option[value='foo']").remove();  

You spelled your ID wrong. You're missing the second y.

Upvotes: 0

dknaack
dknaack

Reputation: 60448

Spelling mistake its not bytpe it is bytype

$("#bytype > option[value='foo']").remove();  

Upvotes: 0

Related Questions