Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
85
rated 0 times [  91] [ 6]  / answers: 1 / hits: 67847  / 11 Years ago, fri, september 13, 2013, 12:00:00

I want to deselect all values with one click without using each id seperately.



I fiddled around for a while, but this deselect only first value. Any suggestions?



This is how I try to deselect:



$( #mybutton ).click(function() {    
$(select).select2('val', '')
});


http://jsfiddle.net/6hZFU/75/


More From » jquery

 Answers
68

Try this instead:



$('select').select2({
placeholder: select me
});

$(#mybutton).click(function () {
$(select).each(function () { //added a each loop here
$(this).select2('val', '')
});
});


Demo here


[#75713] Thursday, September 12, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
jacie

Total Points: 490
Total Questions: 111
Total Answers: 105

Location: Mali
Member since Sat, Feb 12, 2022
2 Years ago
;