How do i select those tr's which all DONT have the example.png in one of their td's? Every image has an anchor, so i thought i may select by that... i never worked with jquery before and its quite confusing^^
$(document).ready(function(){
$("td > a").parent().parent().css("background-color","lime");
});
Here one of my tr's but with only the first anchor/image (it is already too long):
<tr bgcolor='$color'>
<td><a href='request.php?id=$requestid'>#$requestid [show request]</a></td>
<td>$generation </td>
<td>$custname </td>
<td>$platform </td>
<td>$phase </td>
<td>$tmc </td>
<td>$pcstroke </td>
<td>$scstroke </td>
<td>
<a href='myurl.php?selection=" . $flowid."' title='new'>
<img align='center' src='images/new.png'
alt='' style='width:20px; height:20px;' />
</a>
</td>
$status
<td><b>$prelease</b></td>
</tr>;
Thanks in advance.
You can use not
and has
var allTrs = $("tbody tr"), nonExample = allTrs.not(':has(img[src*="example.jpg"])'); nonExample.css("background-color", "red");
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <table> <tbody> <tr><td>foo</td><td><img src="foo.jpg" alt="foo"/></td></tr> <tr><td>example</td><td><img src="example.jpg" alt="example"/></td></tr> <tr><td>bar</td><td><img src="bar.jpg" alt="bar"/></td></tr> <tr><td>example</td><td><img src="example.jpg" alt="example"/></td></tr> </tbody> </table>
Select table's existing img
, and then parent
3 times, as they are expected to be located within anchors tr>td>a>img
:
$(document).ready(function(){
$images = $('table tr>td>a>img'); // Choose the right table selector
$rows = $images.closest('tr');
console.log($rows);
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.