views:

27

answers:

2

How to select all values in drop down list by clicking a button using jQuery in JavaScript?

Thanks in advance

A: 
$(function(){
    $('select').children('option').attr('selected', 'selected');
});

Should do it. Of course you would need a SELECT element with attribute multiple.

jAndy
A: 

This solution works with plain multi-select lists and multi-select lists that have optgroups.

$("select option").attr("selected", "true");

Note: This is the HTML answer, for XHTML selected should equal "selected", rather than true.

Sohnee