bloodscript bloodscript - 24 days ago 10
HTML Question

JQuery select tr when all images in td are not example.png

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&nbsp;&nbsp;</td>
<td>$custname&nbsp;&nbsp;</td>
<td>$platform&nbsp;&nbsp;</td>
<td>$phase&nbsp;&nbsp;</td>
<td>$tmc&nbsp;&nbsp;</td>
<td>$pcstroke&nbsp;&nbsp;</td>
<td>$scstroke&nbsp;&nbsp;</td>
<td>
<a href='myurl.php?selection=" . $flowid."' title='new'>
<img align='center' src='images/new.png'
alt='' style='width:20px; height:20px;' />
</a>&nbsp;&nbsp;
</td>
$status
<td><b>$prelease</b></td>
</tr>;


Thanks in advance.

Answer

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>