2

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

2
  • think you might mean javascript... Commented Sep 7, 2010 at 6:58
  • I have updated the tags to read "JavaScript" in place of "Java" - these are two different languages. Commented Sep 7, 2010 at 7:07

2 Answers 2

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

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

Sign up to request clarification or add additional context in comments.

Comments

1

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.