Ninja In Pajamas
Ninja In Pajamas

Reputation: 97

Insert image element after an element inside a <div>

I am trying to insert an image element after a br tag element which is inside a div.

I am trying with jQuery after as given here

My HTML is like -

<div id="toolTipImage" class="ss-content">

  <input checked="checked" id="OutputType2" name="OutputType" type="radio" value="2"> PDF
  <br>
  <input id="OutputType0" name="OutputType" type="radio" value="0"> HTML

</div>

And I am trying to insert image

var el = { newImg : $("<img>", {class: "profile-image", id: "newImg", src: "path/to/img"}) }

$("toolTipImage").children()[1].after(el.newImg);

Please suggest me how I can achieve this.

Upvotes: 0

Views: 89

Answers (2)

Manoj Yadav
Manoj Yadav

Reputation: 6612

You are missing # before toolTipImage and use children('br') instead of children()[1], try this:

$("#toolTipImage").children('br').after(el.newImg);

OR

$("#toolTipImage br").after($("<img>", {class: "profile-image", id: "newImg", src: "path/to/img"}));

jsFiddle

Upvotes: 0

Ashima
Ashima

Reputation: 4824

Try this -

(el.newImg).insertAfter($("toolTipImage").children()[1]);

Upvotes: 1

Related Questions