1

I have a situation here,

Using JQuery I'm appending some values in drop down list.. Even it is one or two value that appended in drop down list..

For Add,

tableui+='<option value="">'+resourceadd+'</option>';
$('#resourcess').append(tableui); 

When the page reloads automatically the value stored in db.

For example 4 values added in dropdown list (Values are not stored in db), I want to delete last value. I'm using,

$("#resourcess :last-child").remove();

The same condition, I want to delete middle of two values, How to do it??

1 Answer 1

2

Assuming you know the value of the option you want to remove, you could use filter:

$('#resources option').filter(function() {
    return this.value == 'foo'; // insert your value here.
}).remove();

Or an attribute selector:

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

If you don't know the value, but do know the position of the option within the select, you could remove it by index using eq():

$('#resources option').eq(1).remove(); // remove the 2nd option
Sign up to request clarification or add additional context in comments.

3 Comments

In the place of value I'm not getting any values.. I used dynamically to delete values using,, $("#resourcess option[value="+delid+"]").remove();,, But I couldnt delete.. How can i get value in Option????
That should work fine. What is the value of delid, does it match the value of any option? Any errors in the console?
In the hidden text field I'm assigning delid to dynamic deletion ,, I'm iterating delid in while loop. But I couldn't it any option value in delid...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.