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' butto开发者_JAVA技巧n 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?
The :selected
selector will help:
$('.asmSelect :selected').removeAttr('selected');
For example, select a few things and hit Clear: http://jsfiddle.net/ambiguous/QVzB8/
$('.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.
精彩评论