Using jQuery .find() with multiple conditions at the same time?
Posted
by
fuzzybabybunny
on Stack Overflow
See other posts from Stack Overflow
or by fuzzybabybunny
Published on 2014-06-03T09:12:57Z
Indexed on
2014/06/03
9:25 UTC
Read the original article
Hit count: 115
jQuery
|radio-button
I know that there are other ways of grabbing radio button values, but I want to know how to do this with .find().
I only want to log the value of the selected radio button, so it requires finding by two conditions at the same time:
The button with name=area
The button with selected=selected
<div class="radio">
<label>
<input class="track-order-change" type="radio" name="area" id="area1" value="area1" checked="checked">
Area 1
</label>
</div>
<div class="radio">
<label>
<input class="track-order-change" type="radio" name="area" id="area2" value="area2">
Area 2
</label>
</div>
<div class="radio">
<label>
<input class="track-order-change" type="radio" name="area" id="area3" value="area3">
Area 3
</label>
</div>
When anything with the class track-order-change
changes, it will run the function UpdateOrderSubmission.
$('.track-order-change').on('change', function() { updateOrderSubmission() });
I want the updateOrderSubmission
function to console log the value of the radio button that is selected.
var updateOrderSubmission = function() {
var orderSubmission = {
area: $('#submit-initial-form').find('[name=area],[checked=checked]').this.val()
}
console.log(orderSubmission)
};
The code above doesn't work. How do I grab the value of the selected radio button? I need to do .find()
with two conditions (name and checked), not just one condition.
© Stack Overflow or respective owner