Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript show div when the checkbox is checked

  • This topic is empty.
Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #42014
    vanilson
    Participant

    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();
    });

    #121113
    karlpcrowley
    Participant

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

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

    #121115
    TheDoc
    Member

    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

    #121144
    vanilson
    Participant

    karlpcrowley and TheDoc thaks, more simple then my code

    #121145
    karlpcrowley
    Participant

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

Viewing 5 posts - 1 through 5 (of 5 total)
  • The forum ‘JavaScript’ is closed to new topics and replies.