0
<select> <option value="Value 1">Apple</option> <option value="Value 2">Mango</option> <option value="Value 3">Grape</option> <option value="Value 4">Banana</option> </select> 

And I have String "Grape" and the result output should be like this.

<select> <option value="Value 1">Apple</option> <option value="Value 2">Mango</option> <option value="Value 4">Banana</option> </select> 

How to do that?

1
  • Have you tried anything before posting here? Commented Sep 24, 2013 at 10:04

4 Answers 4

1

You'll need to use the jQuery :contains() selector -

:contains() - Select all elements that contain the specified text.

For example:

var txt = "Grape"; var element = $( "#selectElement option:contains('"+ txt +"')" ); element.remove(); // now just remove it 
Sign up to request clarification or add additional context in comments.

Comments

0

You can use contains selector and remove function.

$('select option:contains(Grape)').remove(); 

Working demo

Note: It is better if you give an ID to your select element.

Comments

0

give your select an id(unique) , use id selector to get the select element. and use :contains selector

$(function(){ $('#givenSelectID option:contains("Grape")').remove(); }); 

Comments

0

Check the Js fiddle

http://jsfiddle.net/CZL2y/

$(document).ready(function() { var txt = "Grape"; var element = $( "select option:contains('"+ txt +"')" ); element.remove(); }); 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.