jQuery Prepend an Image

Posted by Tom on Stack Overflow See other posts from Stack Overflow or by Tom
Published on 2010-03-09T09:27:24Z Indexed on 2010/03/09 9:36 UTC
Read the original article Hit count: 269

Filed under:
|
|
|

Hi Guys,

I am trying to add a prepend of an image and then define it's attributes. Little confused as how to do this - currently I have the following but it's not working. The HTML is

<div id="testID" class="test1">
        <div id="testID2" class="test2" ></div>
    </div>

And the JS is

jQuery("#testID2").prepend('<img />').attr({
   src: 'some src.gif',
   alt: '',
   height: '60'
});

I am hoping to achieve

<div id="testID" class="test1">
  <div id="testID2" class="test2" >
      <img src='some src.gif' alt='' height='60' />
  </div>
</div>

Any Ideas?

© Stack Overflow or respective owner

Related posts about prepend

Related posts about image