JQuery addClass if radio button checked?

Try something like $('input. Check'). Is(':checked').

Each(function() { $(this).parent(). AddClass('question-box-active'); }).

I think $(this) is not referring to the radiobutton in your case You could bind the click event of the radio button and decide what to do from there... $(document). Ready(function(){ $("input. Check").

Click(function(){ if($(this). Is(":checked")){ $(this).parent(). AddClass("question-box-active"); } }); }).

Thanks for your answer Kaveman. The form is set up so the page refreshes to display the results of the form after clicking submit. I already have a click function that adds the question-box-active class when the radio button is actively checked by the user.

But when the page refreshed with the results, the class disappears even though the buttons are checked. – Julesfrog Nov 2 at 12:56.

The this you're using is within the function context of the ready handler callback, so it's not pointing to input. Check as you expected. Try something like this instead: $(document).

Ready(function() { var foo = $('input. Check'); if ( foo. Is(':checked') ) { foo.parent().

AddClass('question-box-active'); } }); This is assuming your code logic is correct. I assume, however, that you're trying to do something similar to what Doug provided in another answer. Posting some HTML might help clarify.

Thanks Richard for your help. I added the HTML to my original question hoping this can help. I love jQuery but I'm not so good at it yet.

I tried the code you provided, but the class was added to all parents even to those whose radio buttons were unchecked. I'm still playing around with it to see if I can dig something out, but please if you have any other ideas, let me know. It's driving me crazy.

– Julesfrog Nov 2 at 13:00.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions