select multiple inputs with jquery through attribute 'name'

0

I have a jquery script that selects a particular select through the 'name' attribute and makes some changes to the label of another select:

var selectRecheioGroup = $('select[name=recheio1] .grupoRecheio');

The question is: how can I make so that this selection can also include 2 other selects of names 'recheio2' and 'recheio3'?

    
asked by anonymous 11.02.2017 / 01:05

1 answer

2

With jQuery, you can use all these selectors. For your case, the most practical is ^ . Having $("[title^='Tom']") selects all elements that have the attribute started by Tom . See below how it would be for your example, where I apply a% of% of 20 to the three elements.

$(function () {
  $("select[name^=recheio].grupoRecheio").css("padding", 20);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><selectname="recheio1" class="grupoRecheio">
  <option>Recheio 1</option>
</select>

<select name="recheio2" class="grupoRecheio">
  <option>Recheio 2</option>
</select>

<select name="recheio3" class="grupoRecheio">
  <option>Recheio 3</option>
</select>
    
11.02.2017 / 01:14