dalondon
dalondon

Reputation: 73

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

});

Upvotes: 1

Views: 51

Answers (1)

Mathieu Labrie Parent
Mathieu Labrie Parent

Reputation: 2606

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

    }
});

Upvotes: 2

Related Questions