Search code examples
javascriptjqueryasmselect

Remove all selected items from multiple selects using asmselect


I have multiple asmselect 'select multiple' form inputs on a page I'm developing. I'd like a 'clear' button that resets these to their initial, nothing selected state. I've tried variations of:

$('.asmSelect option[selected]').removeAttr("selected");

With no luck. Could anyone help me out?


Solution

  • The :selected selector will help:

    $('.asmSelect :selected').removeAttr('selected');
    

    For example, select a few things and hit Clear: http://jsfiddle.net/ambiguous/QVzB8/