Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
102
rated 0 times [  106] [ 4]  / answers: 1 / hits: 75005  / 13 Years ago, thu, may 26, 2011, 12:00:00

How would I achieve this:



if($(this).parent().find('input:checked') == true)

{$(this).find('.switch').attr('state','on');}
else{$(this).find('.switch').attr('state','off');}


I know this is wrong but you get the idea I think :). If there is an input that is checked add state on if not state off.


More From » jquery

 Answers
35

Try with



if($(this).parent().find('input').is(':checked')) {
something();
}


This works if there's only one checkbox.


[#92028] Wednesday, May 25, 2011, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
marib

Total Points: 596
Total Questions: 120
Total Answers: 95

Location: Nauru
Member since Thu, Feb 2, 2023
1 Year ago
;