jQuery: Select all options in a Multiple-option Select Box

The following code will programmatically select all the options in a multiple-option Select box. Assuming you have jQuery setup.
$("#selectAllButt").click(function() {
  $("#mySelectList option").each(function() {
    $(this).attr("selected","selected");
  });
});

The following code will programmatically UN-Select all the options in a multiple-option Select box.
$("#selectNoneButt").click(function() {
  $("#mySelectList option").each(function() {
    $(this).removeAttr("selected");
  });
});

No comments:

Post a Comment

Python contextlib for Timing Python code

If you've ever found yourself needing to measure the execution time of specific portions of your Python code, the `contextlib` module o...