MeltingDog MeltingDog - 9 months ago 27
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?


Try this:

    $('.slidetpl img[src=""]').parent().hide();
    $('.slidetpl img:not([src=""])').parent().show(); //Can be removed.