-1

I have some code

<div id="wrapper">
  <span>some content</span>
</div>

I want to prepend this with some content

$( "#wrapper" ).prepend( "<img class='img' src=''>" );

however I don't want it to prepend if the img is already there.

I can't do something like checking how long the wrapper div is because it's content comes from a database and is of variable length.

j71261
  • 1
  • 1
  • 3

1 Answers1

0

Could you do something like

if( $( ".fourfifth" ).prev("img.img").length == 0) {
  $( ".fourfifth" ).prepend( "<img class='img' src=''>" );
}
jonasfh
  • 4,151
  • 2
  • 21
  • 37