Chris Chris - 3 months ago 10
jQuery Question

jquery select remove item

My html code

<select name="test[]" id="test_0">
<option value="">...</option>
<option value="Test 1">Test 1</option>
<option value="Test 2">Test 2</option>
<option value="Test 3">Test 3</option>
</select>
<select name="test[]" id="test_1">
<option value="">...</option>
<option value="Test 1">Test 1</option>
<option value="Test 2">Test 2</option>
<option value="Test 3">Test 3</option>
</select>


My jquery code

$("#test_0 option:eq(1)").remove();
$("#test_1 option:eq(2)").remove();


If I remove an item, how can I keep it in memory to replace it later at the same place ?

Thanks for your help...

Chris

Answer

You could hide it:

 $("#test_0 option:eq(1)").hide();
 $("#test_1 option:eq(2)").hide();

But im not sure it works on all browsers. Otherwise you could clone it and save it in a variable and then remove it:

var option1 = $("#test_0 option:eq(1)").
var option1clone = option1.clone();
//now remove the original
option1.remove
Comments