I want to get all the inputs:
-
that are checkboxes,
-
that are checked and
-
have the class name that includes “-required”.
I have this, and have tried several variation, but nothing works:
$("input:checkbox[class*='-required']:checked");
example html:
<form name="myform" method="POST">
<div id="checkFruits">FRUITS: </div>
<input type="checkbox" id="chkFruit" class="chkFruit test-234-required" name="fruit" value="Apples" />Apples <br />
<input type="checkbox" id="chkFruit" class="chkFruit test-234-required" name="fruits" value="Oranges" />Oranges <br />
<input type="checkbox" id="chkFruit" class="chkFruit test-234-required" name="fruits" value="Pears" />Pears <br />
<input type="checkbox" id="chkFruit" class="chkFruit test-234-required" name="fruits" value="Grapes" />Grapes <br /><br />
<input type="button" id="btnCheckFruit" value="Check Fruits" name="btnCheckFruit" />
<hr />
<div id="checkCars">CARS: </div>
<input type="checkbox" id="chkCar" class="chkCar" name="fruit" value="Lexus" />Lexus <br />
<input type="checkbox" id="chkCar" class="chkCar" name="fruits" value="Maxima" />Maxima <br />
<input type="checkbox" id="chkCar" class="chkCar" name="fruits" value="Cadillac" />Cadillac <br />
<input type="checkbox" id="chkCar" class="chkCar" name="fruits" value="Lincoln" />Lincoln <br /><br />
<input type="button" id="btnCheckCar" value="Check Cars" name="btnCheckCar" />
<hr />
<ul>
<li>foo</li>
<li>bar</li>
</ul>
</form>
You can use
$("input:checkbox:checked[class*='-required']")as the selectorHere is a working fiddle