javascript - How to select tr whose first and second td contains specific value? -
i have table looks this:
code follows:
<table id="table1"> <tr> <td>hu</td> <td>bip</td> <td>pannon</td> </tr> <tr> <td>hu</td> <td>bip</td> <td>t-mobile</td> </tr> <tr> <td>hu</td> <td>bip</td> <td>vodafone</td> </tr> <tr> <td>hu</td> <td>fun</td> <td>pannon</td> </tr> <tr> <td>hu</td> <td>fun</td> <td>t-mobile</td> </tr> <tr> <td>hu</td> <td>fun</td> <td>vodafone</td> </tr> </table>
how select last <tr>
first <td>
contains "hu" , second <td>
contains "bip".
i tried select this:
$('#table1').find('tr td:first-child:contains("hu") td:nth-child(2):contains("bip")').last();
shows nothing
and this:
$('#table1').find('tr td:first-child:contains("hu")').parent().each(function(i,e){ console.log($(e).children('td:contains("bip")').parent().last()); });
doesn't show last tr
of them(that contains "hu" , "bip") instead.
any idea?
you can this:
$(document).ready(function() { var target = $('table tr td:first-child:contains("hu")').parent().find('td:nth-child(2):contains("bip")').last().parent(); console.log(target.html()); });
<script src="https:code.jquery.com/jquery-2.2.4.min.js" integrity="sha256-bbhdlvqf/xty9gja0dq3hiwqf8lacrtxxzkrutelt44=" crossorigin="anonymous"></script> <table> <tr> <td>hu</td> <td>bip</td> <td>pannon</td> </tr> <tr> <td>hu</td> <td>bip</td> <td>t-mobile</td> </tr> <tr> <td>hu</td> <td>bip</td> <td>vodafone</td> </tr> <tr> <td>hu</td> <td>fun</td> <td>pannon</td> </tr> <tr> <td>hu</td> <td>fun</td> <td>t-mobile</td> </tr> <tr> <td>hu</td> <td>fun</td> <td>vodafone</td> </tr> </table>
it first selects first td
containing "hu" selects parent tr
, again filters result finding second td
containing "bip" , selects last matched element.
Comments
Post a Comment