Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jquery get only first checkbox of a tr

I want to check if the first checkbox in a tr is selected not all the checkbox that is found in this tr.

For the time being i have this code :

var b = false;
$j('#tb1 td input:checkbox').each(function(){ 
      if($j(this).is(':checked')){
    b = true;
      }
});

this check if there is at least one checkbox check but if i add this to my selector :

$j('#tb1 td input:first:checkbox').each(function(){ 
      if($j(this).is(':checked')){
    b = true;
      }
});

it check for only the first row not for all the rows and only the first checkbox. How can i achieve this by using the "first" selector ? Thanks in advance

like image 284
vanessen Avatar asked Sep 19 '13 06:09

vanessen


2 Answers

Try

var b = false;
$j('#tb1 tr').find('input:checkbox:first').each(function(){ 
    if(this.checked){
        b = true;
    }
});
like image 94
Arun P Johny Avatar answered Sep 29 '22 23:09

Arun P Johny


Your jquery code is wrong, you are using the correct selector but in wrong place..try this

$j('#tb1 td input:checkbox:first').

More infor about :First is here

like image 20
nrsharma Avatar answered Sep 30 '22 00:09

nrsharma