[help!] Trouble changing checkbox state with jQuery-JS
Hi, I need some help with this. I'm trying to make a game (you'll see it when I finish it :D), and there's is a point where jQuery is running an unexpected behavior: I want to check if a checkbox is checked or not and change its state. My actual code is here. I've tried some solutions but no one is running well, I'll explain before code some issues: $change = $('#' + $lie); if ($change.prop('checked', true)) { $change.prop('checked',false); } else if ($change.prop('checked', false)) { $change.prop('checked', true); } As you can see, the $change var is not a static one. Previously, I have some checkers with its unique ID. I verify all ID checkers and, with comparing characters of these ID I know which is incorrect (this is part of the game). Then, $lie is a text that corresponds with a concrete #id, that's why I make the line $change = ('#', + $lie); -> to convert the string into a valid ID to play with. Then, I have to find the state of the checker. If it's checked I have to uncheck, and reverse. Here, code is making some mistakes: - never checks, only unchecks - sometimes uncheck correct one, sometimes no - it's supossed to act ONCE, but sometimes uncheck two checkboxes :O I'm going crazy with it, I've read many stackoverflow tips, documentation about .prop(), .is(), .checked and many other possible specs, but nothing helping me. I'm not sure if you would need a bigger piece of code to get more info, but after many tries and debugging I'm pretty sure the problem is inside these. Thanks for your help!