bloodscript bloodscript - 1 year ago 61
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^^

$("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>
<a href='myurl.php?selection=" . $flowid."' title='new'>
<img align='center' src='images/new.png'
alt='' style='width:20px; height:20px;' />

Thanks in advance.

Answer Source

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=""></script>
    <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>

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download