:selected Selector

Selects all elements that are 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.

<select name="garden" multiple="multiple">
  <option selected="selected">Shrubs</option>
  <option selected="selected">Bushes</option>
div {
  color: red;
  .change(function () {
    var str = "";
    $("select option:selected").each(function () {
      str += $(this).text() + " ";

Looking for a Web Developer?


Hi! I'm Basti, author of this site. If you are looking for a web developer with 15+ years of experience, holla at me!

Be it the good 'ol jQuery, vanilla JS or modern frameworks like Vue and Svelte, front- or backend, I can help you.

Just write me at jobs@jqapi.com :)