JQuery check if prepend failed
<p>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().  </p>

<p>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.</p>

<p>Tried this:</p>

<pre><code>$('.query').each(function(i) {
  var elm=$(this);
  if (elm.prepend('&lt;img class="fold" src="/img/fold.png" /&gt;').find('img.fold').length==0) {
    elm.before('&lt;img class="fold" src="/img/fold.png" /&gt;');
  }
});
</code></pre>

<p>On:</p>

<pre><code>&lt;span class="query"&gt;
  &lt;img alt="blah" src="img/banner.jpg" height="422" width="952" /&gt;
&lt;/span&gt;
&lt;span class="query"&gt;
  &lt;p&gt;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&lt;/p&gt;
&lt;/span&gt;
</code></pre>

<p>No answers so I have a work around for now:</p>

<pre><code>if (elm[0].tagName.toLowerCase()=="img") {
    elm.before('&lt;img class="fold" src="/img/fold.png" /&gt;');
}
else {
    elm.prepend('&lt;img class="fold" src="/img/fold.png" /&gt;')
}
</code></pre>
