:selected Selector in JQuery

:selected Selector – jQuery API


version added: 1.0jQuery(‘:selected’)

The :selected selector works for <option> elements. It does not work for checkboxes or radio inputs; use :checked for them.


Attaches a change event to the select that gets the text for each selected option and writes them in the div. It then triggers the event for the initial text draw.

<!DOCTYPE html>
  div { color:red; }
  <script src="/scripts/jquery-1.4.js"></script>
	<select name="garden" multiple="multiple">

    <option selected="selected">Shrubs</option>
    <option selected="selected">Bushes</option>


    $("select").change(function () {
          var str = "";
          $("select option:selected").each(function () {
                str += $(this).text() + " ";

Leave a Reply

Your email address will not be published. Required fields are marked *