MeltingDog MeltingDog - 2 years ago 62
jQuery Question

Difficulty hiding image with no src

I have a series of the following elements:

<div class="slidetpl">
<img src >

I want to hide .slidetpl if the image has no source. To do that I have tried the following:

$('.slidetpl img').each(function () {
if (this.src.length == 0) {

But this is not working.

Can anyone point me in the right direction or tell me what I've done wrong?

Answer Source

Try this:

    $('.slidetpl img[src=""]').parent().hide();
    $('.slidetpl img:not([src=""])').parent().show(); //Can be removed.
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download