Search code examples
jqueryhtml-selectdetach

jquery how to re-detach a detach on option


I need help concerning following code: http://jsfiddle.net/8PsdE/

<SELECT ID="pizzasize" NAME="pizzasize">
<OPTION VALUE="s">small
<OPTION VALUE="m">medium
<OPTION VALUE="l">large
</SELECT>

    $(function() {
   $('#pizzasize > option[value*="m"]').detach();
});

How can I add the detached option back again? Thx in advance...


Solution

  • Get a reference to the options you have selected, then you can detach them or do anything else with them using that reference:

    $(function() {
      var theOptions = $('#pizzasize > option[value*="m"]');
      theOptions.detach();
    
      // Do other things with theOptions
    });