Vincent Teyssier February 2016

jQuery selector for all inputs checked or other type than radio

I'm totally lost about how to do the following: - select all checked radio AND all other inputs of different type than radio which are inside one div

selecting all input should be $(':input') selecting checked radio should be $( "input[type=radio]:checked") and of course inside the div $('#mydiv')

$('#mydiv :input') matches 2 conditions: all inputs inside the div. I can of course test the type property after, but wondering if I could do it in one only selector ?

Answers


dev_masta February 2016

Documentation: Multiple Selector (“selector1, selector2, selectorN”)

If you have 2 selectors, for example:

$("div#id")

and

$("p.class")

you can combine them and use them together like this:

$("div#id, p.class")

So, in your case, you should use:

$("#mydiv :input[type=radio]:checked, #mydiv :input:not([type=radio])")

Post Status

Asked in February 2016
Viewed 1,028 times
Voted 11
Answered 1 times

Search




Leave an answer