Search code examples
javascriptjqueryhtmlinsertafter

how can I insert Tags HTML with javascript in a precise position


I need to add HTML Tags in a precise position using Javascript

<div id="myId">
   <div id="addAfter"><div>
   <***here I need to add a set off HTML Tags***>
   <div ><div>
   <div><div>
</div>

javascript code

  var ol = '<ol id ="div_blue"><li><img id="blueUp" src="<c:url    value="/resources/style/images/btup.png"/>" alt =""/></li><li>....</li>< /ol>' ;
  $("#myId").InsertInPosition2(ol);

but how to define InsertInPosition2?

thanks

imprim ecran

enter image description here


Solution

  • Use .after()

    $("#addAfter").after(ol);
    

    Demo: Fiddle

    If you want to add the element with reference to the parent element then

    $("#myId").children().first().after(ol);
    

    Demo: Fiddle