Link to home
Start Free TrialLog in
Avatar of vbnetcoder
vbnetcoder

asked on

Remove element from a dropdown in jquery

How do i remove an item programmatically from a drop down list in jquery?

Specifically, I want to remove an item where the value is "N". How would i do so...

This is how they are being added:


$dd.append($('<option>').val("N").text("Nancy"));
Avatar of Jon Norman
Jon Norman
Flag of United Kingdom of Great Britain and Northern Ireland image

$dd.find("option [value=\"N\"]").remove();
ASKER CERTIFIED SOLUTION
Avatar of soupBoy
soupBoy
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
@JonNorman

Sorry, I walked away from my computer and then completed my post.  Didn't mean to make it look like I was copying your post!

Just curious, why are you escaping the quotes?  I haven't done that before....

-Chris
Avatar of vbnetcoder
vbnetcoder

ASKER

This syntax posted by soupBoy worked:

  $dd.find('option[value="N"]').remove();
ty
Hi Chris,

option[value="N"] is just a string, if you delimit the string with single quotes then you can use 'option[value="N"]', if you delimit the string with double quotes you need to excape the double quotes inside the string "option[value=\"N\"]" - http://jsfiddle.net/JonNorman/34UHB/