David Tan David Tan - 6 months ago 10
Javascript Question

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?

Answer

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>

Comments