Any ideas on how I would test if prepend() succeeds? Prepend() doesn't work on an image tag of course so I need to perform before().
I'm trying to prepend an image to all spans with a class of .query, but cannot get it to work on spans that contain self closing tags like images.
Tried this:
$('.query').each(function(i) {
var elm=$(this);
if (elm.prepend('<img class="fold" src="/img/fold.png" />').find('img.fold').length==0) {
elm.before('<img class="fold" src="/img/fold.png" />');
}
});
On:
<span class="query">
<img alt="blah" src="img/banner.jpg" height="422" width="952" />
</span>
<span class="query">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum ornare, tellus in posuere viverra, dui dolor lacinia elit, vitae vestibulum nuluris condimentum. Donec vel mauris t sed sit amet. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos</p>
</span>
No answers so I have a work around for now:
if (elm[0].tagName.toLowerCase()=="img") {
elm.before('<img class="fold" src="/img/fold.png" />');
}
else {
elm.prepend('<img class="fold" src="/img/fold.png" />')
}