Miguel
Miguel

Reputation: 2079

how to properly append div at run time?

Hello im trying to wrap a div with another div by using jquery append and im having one hell of a time. here is my div

<div id ="one" class="PortalBox" data-title="Concur">
    <div class = "localContent">
    FGDDDDDDDDDfdgdfffffffff
    dfgggggggggggggggggggggggggg
    dfggggggggggggggggggggggggg
    fgddddddddddddddddddddddddd
    fgddddddddddddd.
</div>

</div>

now what i would like to do is add an open div tag right above and then close it after the closing tag related to local content. here is what i tried and i keep failing miserably.

   /*open div*/
    $('.localContent').each(function(idx, ele){
        //alert(ele.className);
        $('<div class="ab_Box1d" style ="width:630px">').insertBefore($(ele))
                })
    /*close the div*/   
    $('.localContent').each(function(idx, ele){
        //alert(ele.className);
        $('</div>').insertAfter($(ele))
                })

what is the proper way to do this? any help would be most appreciative.

Upvotes: 0

Views: 345

Answers (1)

Joel
Joel

Reputation: 11851

I think you want to use jQuery's wrap() function.

$('.localContent').wrap('<div class="ab_Box1d" style="width:630px"/>');

Upvotes: 2

Related Questions