davidtgq
davidtgq

Reputation: 4000

Select <select> elements that have the multiple attribute

I don't know what these are called, the thing that the element is (not the class or id), for example:

<select multiple class="form-control" id="exampleSelect2">
  <option>1</option>
  <option>2</option>
</select>

Source

In this case, I want to select $('select multiple'), so that it picks up any element with both the select and multiple names. What is the syntax for this?

Upvotes: 2

Views: 464

Answers (1)

Nenad Vracar
Nenad Vracar

Reputation: 122027

multiple is boolean attribute and you can use attr selector like this $('select[multiple]')

$('select[multiple]').css('background', 'blue');
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<select multiple class="form-control" id="exampleSelect2">
  <option>1</option>
  <option>2</option>
</select>

Upvotes: 6

Related Questions