views:

51

answers:

3

In a div there are these check boxes(name="val1") and after a certain operation these check boxes are removed

<div name="navigation_b">
    <label id="selectall">
        select all 
        <input type="checkbox" name="selectall" />
    </label>
    <input type="checkbox" name="val1" />   
    <input type="checkbox" name="val1" />   
    <input type="checkbox" name="val1" />   
    <input type="checkbox" name="val1" />   
    <input type="checkbox" name="val1" />   
</div>

If all the checkboxes(name =val1) are removed then the selectall should not be visible.How to do this using jquery

A: 

You could check to see if there are any of the checkboxes and if not then remove the label

if($('input:checkbox[name="val1"]').length) {
    // do something
}
else {
    // do something else
}

the above is untested but i think it's pretty close.

griegs
A: 
if( $("input:checkbox[name='val1']").length==0)
{
       $("input:checkbox[name='selectall']")
      .hide();
}

Source is here, and here

Edit

You could hide the entire label which contains selectall -

if( $("input:checkbox[name='val1']").length==0)
{
       $("label#selectall")
      .hide();
}
Night Shade
A: 

If your question is to auto-show the select all checkbox, when the others are removed, I don't think that is possible with jQuery, unless there is an event that jQuery sports which would fire when an element is removed. You'll have to show the select all checkbox manually may be by using one of the fine solutions provided in the other answers.

Shrikant Sharat