简体   繁体   中英

Show/Hide div with checkboxes using classes multiple times on a page

I am having trouble getting my script to work here. I am trying to target the show me span when the checkboxes are checked and it's not working.

Here is the code and link to fiddle: http://jsfiddle.net/dalond/nonyg6sm/

$('.single').live('change', ':checkbox', function() {
var target = $(this).closest('.single').prev().find('.showMe');
if ($(this).find('input:checked').length == 0) {
    target.hide();
} else {
    target.show();
}

});

I got it worked : http://jsfiddle.net/nonyg6sm/3/

$('input[type=checkbox]').click(function() {

    var target = $(this).closest('.NoEd').prevAll(".Subs:first").find(".showMe");

    if (this.checked) {
        target.show();
    } else {
        target.hide();
    }
});

You can modify it to feet your need.

UPDATE

http://jsfiddle.net/nonyg6sm/4/

$('input[type=checkbox]').click(function() {

    var target = $(this).closest('.NoEd').prevAll(".Subs:first").find(".showMe");

    if ($(this).closest('.NoEd').find("input[type=checkbox]:checked").length == 0) {
        target.hide();        
    } else {
        target.show();

    }
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM