jquery not(:contains) not working -


i using following code filter rows not contains specific text.

var x = "cotton";  $('#divqualcodefuncpmtype > table tbody tr:gt(0) td:eq(2) span:not(:contains(' + x + '))').closest("tr"); 

it results in no row if use following code filter rows specific text works fine, seems there wrong implementation of not.

$('#divqualcodefuncpmtype > table tbody tr:gt(0) td:eq(2) span:contains(' + x + ')').closest("tr"); 

can please correct wrong here. appreciated.

update: html markup

    <table class="setdwpparametertabstyle">         <tbody>             <tr class="gridheadersystemparamter">                 <td style="display: none">                     map id                 </td>                 <td style="display: none; width: 30px;">                     type id                 </td>                 <td style="width: 300px">                     material type                 </td>             </tr>              <tr>                 <td style="display: none">                     <span id="lblmapid">10</span>                 </td>                 <td style="display: none">                     <span id="label3">60</span>                 </td>                 <td>                     <span id="label1">100% cotton</span>                 </td>             </tr>              <tr>                 <td style="display: none">                     <span id="lblmapid">20</span>                 </td>                 <td style="display: none">                     <span id="label3">70</span>                 </td>                 <td>                     <span id="label1">100% cotton</span>                 </td>             </tr>         </tbody>     <table> 

the problem td:eq(2), matches third td of all matching rows (not third 1 in each row)!

e.g. problem shown here http://jsfiddle.net/trueblueaussie/a9mck46m/2/

use nth-child(3) instead:

$('#divqualcodefuncpmtype > table tbody tr:gt(0) td:nth-child(3) span:contains("' + x + '")').closest("tr"); 

jsfiddle: http://jsfiddle.net/trueblueaussie/a9mck46m/1/

td:nth-child(3) match each td 3rd child. note nth-child starts @ 1 (to compatible css equivalent).

update: "filter friend":

once start complex queries, is easier switch using filter function returns true or false include/exclude items.

e.g.

var $el = $('#divqualcodefuncpmtype > table tbody tr:gt(0)').filter(function(){     return $('td:nth-child(3) span:contains("' + x + '")', this); }); 

jsfiddle: http://jsfiddle.net/trueblueaussie/a9mck46m/4/

your additional question, below, asked combining searches:

the following returned true value if both items found:

var x = "cotton"; var y = "fish"; var $el = $('#divqualcodefuncpmtype > table tbody tr:gt(0)').filter(function(){     return $(this).find('td:nth-child(3) span:contains("' + x + '")').length && $(this).find('td:nth-child(5) span:contains("' + y + '")').length; }); 

jsfiddle: http://jsfiddle.net/trueblueaussie/a9mck46m/5/


Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -