0

I cant get this checkbox to check the checkboxs which are not hidden

Basiclly I need it to not check any check box in the table which is hidden from view

ui-tableFilter-hidden
$("input:checkbox.checkall").live('click', function(event){
    var checkedStatus = this.checked;
    if(!$('table tbody tr').hasClass('ui-tableFilter-hidden'))
    {
        $("td.small input:checkbox").each(function() {
            this.checked = checkedStatus;
        });
    }
});

Quick fix was to replace the above code with this one

$("input:checkbox.checkall").live('click', function(event){
    var checkedStatus = this.checked;

        $("td.small input[type=checkbox]:visible").each(function() {
            this.checked = checkedStatus;
        });

});
2
  • Can you put together a jsFiddle? Commented Oct 23, 2011 at 23:17
  • 1
    You should also use the change event in your answer. Commented Oct 23, 2011 at 23:28

2 Answers 2

1

Your IF check and the EACH loop are unrelated in the code above. The IF will evaluate to true at some point and then the EACH loop will iterate through all checkboxes matching the selector, regardless of what you checked in the IF.

Try something like this instead...

$('table tbody tr')each(function(){
    if(!$(this).hasClass('ui-tableFilter-hidden')){
           $(this).find("td.small input:checkbox").each(function() {
                this.checked = checkedStatus;
            });
        }
    }
Sign up to request clarification or add additional context in comments.

1 Comment

No need to loop through the rows -- as the OP figured out himself, you can use the :visible pseudo selector, or as I posted, you can search for all rows without the class ui-tableFilter-hidden.
0

Ideally, you should be using the change event, since inputs can be altered with more than just clicks. You can also just find all rows with the ui-tableFilter-hidden, then check the appropriate checkboxes. I also use prop to identify the checked state of the box, available as of jQuery 1.6, although this.checked should work as well.

$("input:checkbox.checkall").change(function(){
    var jCheckAll = $(this);
    var checkedStatus = jCheckAll.prop("checked");
    var jRows = $('table tbody tr:not(.ui-tableFilter-hidden)');
    jRows.find("td.small input:checkbox").prop("checked",checkedStatus);
});

2 Comments

I ended up using $('input[type=checkbox]:visible')
Edited my code to reflect the fact that you wanted rows that don't have that class. Your method is simpler, though! Just make sure to use the change event.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.