Sri
Sri

Reputation: 131

issue in jquery radio button selection

I am not much more flexible with jquery. I have some li tags and for each li tag, I have one input tag of type radio like:

<li><input type='radio' value='cool' name='radiooption' id='2'>2</li>
<li class='answered'><input type='radio' name='radiooption' value='cool1' id='3'>3</li>
<li><input type='radio' value='cool' name='radiooption' id='4'>4</li>
<li><input type='radio' value='cool' name='radiooption' id='5'>5</li>

Now by jquery how to add checked="checked" for radio button which is under li tag having class='answered'?

Please guide me.

Upvotes: 2

Views: 68

Answers (2)

Leigh Ciechanowski
Leigh Ciechanowski

Reputation: 1317

$('.answered').find('input').attr('checked', 'checked');

Upvotes: 1

billyonecan
billyonecan

Reputation: 20250

You need to fix your markup first (you're missing the closing </li>s). As for the jQuery, something like this should do the trick:-

$('li.answered').children('input[type="radio"]').prop('checked', true);

Upvotes: 1

Related Questions