Grow your CSS skills. Land your dream job.

show div when the checkbox is checked

  • # January 15, 2013 at 6:16 pm

    hi guys, I got a checkbox and when the chebox is checked I want to show a div and when is unchecked I want to hide a div, but the code that I write isn’t working:

    $(‘#form’).hide();
    $(‘.chk’).on(‘click’, function () {
    if ($(this).is(‘:checked’))
    $(‘#form’).show();

    else

    $(‘#form’).hide();
    });

    # January 15, 2013 at 7:00 pm

    Here’s some code that will do the job but you should change the selectors I’ve used

    http://codepen.io/karlpcrowley/pen/FHgct

    # January 15, 2013 at 7:12 pm

    Sorry, @karlpcrowley, two in a row makes it look like I’m a dick! Minor tweak since `live()` is deprecated:

    http://codepen.io/ggilmore/pen/teFny

    # January 16, 2013 at 1:56 am

    karlpcrowley and TheDoc thaks, more simple then my code

    # January 16, 2013 at 3:25 am

    @TheDoc You’re definitely not a dick, it’s the reason we’re here :)

Viewing 5 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic.

*May or may not contain any actual "CSS" or "Tricks".