Reputation: 673
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>
Upvotes: 1
Views: 78
Reputation: 1126
try this selector :
$("input:checked[type='checkbox'][class*='-required']");
http://jsfiddle.net/jbduzan/G64xR/1/
edit : fiddle with your example
http://jsfiddle.net/jbduzan/G64xR/2/
Upvotes: 2
Reputation: 18237
try this selector
$('input.-required:checkbox:checked')
here's an live example
Upvotes: 2
Reputation: 13461
You can use $("input:checkbox:checked[class*='-required']")
as the selector
Here is a working fiddle
Upvotes: 1