One of the things I like jquery for is that there is a multitude of ways to do something. I like options. Clearing a drop down in jquery is no
exception. Here are some ways to do it. Keep in mind that these are only on the client side.
All of these can be seen here: http://jsfiddle.net/zy22N/
Assume you have the following html:
[code language=”html”]
<select id="test">
<option value=’1′>1</option>
<option value=’2′>2</option>
<option value=’3′>3</option>
<option value=’4′>4</option>
</select>
<a href="#" id="option1" >Click me</a>
<a href="#" id="option2" >Click me</a>
<a href="#" id="option3" >Click me</a>
[/code]
Option 1:
[code language=”js”]
$(‘#option1’).click(function() {
$(‘#test option’).remove();
});
[/code]
Option2:
[code language=”js”]
$(‘#option2’).click(function() {
$("#test").html("<option selected=\"selected\"></option>");
});
[/code]
Option 3:
[code language=”js”]
$(‘#option3′).click(function() {
document.getElementById("test").options.length = 0;
});
[/code]
As a bonus you can remove one element by using:
[code language=”js”]
$("#test option[value=’2’]").remove();
[/code]
Looking for quality web hosting? Look no further than Arvixe Web Hosting!