Click here to Skip to main content
15,891,423 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am beginner in jquery. please help me in that.
I have checkbox

ASP.NET
<div class="small-12 large-5 columns">
       <label for="checkbox1">
           <asp:CheckBox runat="server" ID="chkRemember" />
           <span class="custom checkbox "></span>Remember My password
       </label>
   </div>


I want to change the class of the span to "custom checkbox checked" when the checkbox checked. and change it to "custom checkbox disabled" when it is not checked. in jquery
Posted
Updated 1-Oct-13 1:51am
v2

1 solution

Hey there,

This is how you do that:
HTML:
ASP.NET
<div class="small-12 large-5 columns">
        <label for="checkbox1">
            <asp:checkbox runat="server" id="chkRemember" onclick="MyCheckedChanged(this)" xmlns:asp="#unknown" />
            <span id="spnChk" class="custom checkbox"></span>Remember My password
        </label>
    </div>

JavaScript:
JavaScript
function MyCheckedChanged(checkbox) {
            if (checkbox.checked) {
                $("#spnChk").removeClass("disabled");
                $("#spnChk").addClass("checked");
            } else {
                $("#spnChk").removeClass("checked");
                $("#spnChk").addClass("disabled");
            }
        }


Hope it helps.

Azee...
 
Share this answer
 
Comments
Brian A Stephens 1-Oct-13 11:03am    
Or simplify the function to one line:
$("#spnChk").toggleClass("disabled checked");

You just have to add the "disabled" class to spnChk so it defaults correctly.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900