Ozzy
Ozzy

Reputation: 905

How to hide/show content when checkbox is checked/unchecked?

I'm working on a form for a client and he has given me the task to create a show/hide effect when certain checkbox in unselected.

Upvotes: 4

Views: 2710

Answers (2)

Razor
Razor

Reputation: 29588

$("#checkboxID").change(function() { $("#targetToHideAndShow").toggle() } );

Upvotes: 2

Kelsey
Kelsey

Reputation: 47726

This function should do it:

$("#yourCheckboxID").click(function ()
{
    if ($("#yourCheckboxID").attr("checked"))
    {
        $("#yourDivID").show();
    }
    else
    {
        $("#yourDivID").hide();
    }              
});

It will hide or show a specific div based on a checkbox. I wasn't sure exactly what you were trying to hide or show so I just assumed a div.

Upvotes: 4

Related Questions