Hi, I just started using jQuery and am trying to achieve the below;
Two radio button, when I click on any one the label for checked radio class should change, and when I click other one the label class should change here while the unchecked should fall back to default class. Below is the code I tried it applies the class but then it does not revert back to default when other radio button is checked. Any help is appreciated. Thank you! --------------------------------------- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http:// www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <script type="text/javascript" src="http://code.jquery.com/jquery- latest.js"></script> <script> $(document).ready(function(){ $("input:checked + label").addClass("hilite"); $("label").click(function () { $(this).toggleClass("hilite"); }); }); </script> <title>Radio Toggle</title> <style type="text/css"> label { color:black; margin:5px 1px; cursor:pointer;padding:2px 5px; } label.hilite { background:blue;color:white; } </style> </head> <body> <form action="" method="get"> <input name="" type="radio" value="" id="yes" checked="checked" / ><label for="yes">check me</label> <input name="" type="radio" value="" id="no" /><label for="no">check me not</label> </form> </body> </html> ---------------------------------------