user1176783
user1176783

Reputation: 673

Jquery: how do I reference this selector

I want to get all the inputs:

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

Answers (3)

jbduzan
jbduzan

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

Jorge
Jorge

Reputation: 18237

try this selector

$('input.-required:checkbox:checked')

here's an live example

demo

Upvotes: 2

Prasenjit Kumar Nag
Prasenjit Kumar Nag

Reputation: 13461

You can use $("input:checkbox:checked[class*='-required']") as the selector

Here is a working fiddle

Upvotes: 1

Related Questions