0

I am making a multiselectlist in MVC. The html for it comes out like this:

<select multiple="multiple"  id="foo" name="foo">
<option value="15">Doctor of Medicine</option>
<option value="10">Doctor of Osteopathy</option>
...

I am trying to remove or hide an option using jquery:

$('#foo option:contains("' + removeThis + '")').remove();

or

$('#foo option:contains("' + removeThis + '")').hide();

The first does nothing. The second seems to add a display: none to the html, but it has no affect on the list item (you can still see it). Why not? How do I edit it?

Tushar Gupta - curioustushar
  • 58,085
  • 24
  • 103
  • 107
user1442605
  • 192
  • 1
  • 8
  • A similar question can be found here http://stackoverflow.com/questions/375508/removing-an-item-from-a-select-box – Adriano Silva Jan 11 '13 at 14:11
  • Is there a reason you need to do this on the front end? A better approach would be to edit the `IEnumerable<>` you provide to the `MultiSelectList` in the controller. – Rory McCrossan Jan 11 '13 at 14:12
  • The question above has the same problem for me, that the changes don't seem to have any effect – user1442605 Jan 11 '13 at 15:08
  • @RoryMcCrossan Doy...I've been working in a .cshtml page, I can just use razor there...will give it a try. – user1442605 Jan 11 '13 at 15:08

1 Answers1

0

Mystery solved...turns out my late coworker was using this multiselect widget. I needed to use the UI to refresh it.

Moral of the story: fully research the existing code - it helps to know where an object comes from before trying to edit it.

user1442605
  • 192
  • 1
  • 8