javascript - Set boolVar to true if all TD has text otherwise set it to false -


i have html code:

<table id="contenedorfabricantes" style="" class="table table-condensed"> <thead>     <tr class="tablehead">         <th><input type="checkbox" name="togglecheckboxfabricantes" id="togglecheckboxfabricantes"></th>         <th>fabricante</th>         <th>dirección</th>         <th>país</th>         <th>teléfono</th>     </tr> </thead> <tbody id="fabricantebody">     <tr>         <td><input type="checkbox" value="1"></td>         <td>distribuidor1</td><td>8768 dewy apple wynd, foxtrap, montana</td>         <td id="fabtd-1" class="has_pais"></td>         <td>4061782946</td>         <td><a data-backdrop="static" data-target="#addpaisesfabricante" data-toggle="modal" id="1" class="editable-pais" href="#"><i title="" data-placement="top" data-toggle="tooltip" class="fa fa-plus-circle" data-original-title="agregar países"></i></a></td>     </tr>     <tr>         <td><input type="checkbox" value="1"></td>         <td>distribuidor1</td><td>8768 dewy apple wynd, foxtrap, montana</td>         <td id="fabtd-1" class="has_pais">country1, country2</td>         <td>4061782946</td>         <td><a data-backdrop="static" data-target="#addpaisesfabricante" data-toggle="modal" id="1" class="editable-pais" href="#"><i title="" data-placement="top" data-toggle="tooltip" class="fa fa-plus-circle" data-original-title="agregar países"></i></a></td>     </tr> </tbody> 

i'm trying set boolvar false if @ least 1 td.has_pais has not text meaning "" , i'm doing:

$(document).ready(function(){   var boolvar = true,   haspaises = $('#fabricantebody tr td:nth-child(3)').each(function () {       $(this).text() === "" ? boolvar = false : boolvar = true;   });    console.log(boolvar); }); 

but i'm doing wrong since boolvar gets true , provided html example should false, can tell me i'm failing?

you can use :empty() , check length of collection

var boolvar = $('#fabricantebody .has_pais:empty').length > 0; 

Comments

Popular posts from this blog

matlab - "Contour not rendered for non-finite ZData" -

delphi - Indy UDP Read Contents of Adata -

javascript - Any ideas when Firefox is likely to implement lengthAdjust and textLength? -