Question

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?

Was it helpful?

Solution

The :selected selector will help:

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

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

OTHER TIPS

$('.asmSelect').each(function(){this.selectedIndex = -1});

You could try that.

Edit: Tested

works. You can see here

Is something like this what you're looking for?

http://jsfiddle.net/ebiewener/9Ejdz/2/

After getting stuck with this issue for some 90 minutes I came up with this simple yet effective solution: just pretent asmListItemRemove was clicked like this:

$('.asmListItemRemove').trigger('click');

Me happy :)

PS.: The solution marked as correct did NOT work for me, as ist took the data out of the select mode but did'nt remove the selectors. When I removed them by jquery .remove() or .hide() the targeted prop would not be selectable next time the select was clicked.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top