开发者

With Jquery on page loading I want to move a div from its original place

I'm trying to do the following: Get a DIV that is inside a hidden div in the page and put it开发者_开发问答 next to another element via jquery. Is there any simple way to do that?


Let's suppose that this is your html:

    <div class="hidden-div">
        <div id="MyDiv"> I want to move it </div>
    </div>
    <div id="target">
        <a href="#" class="crazyLink"> link </a>
    </div>

And your js should look like:

$(document).ready(function(){
    $('#MyDiv').insertAfter('#target a :last') ;
});

This would put "MyDiv" next to the crazyLink anchor


Here's one approach.

sourceDiv = $('div#your_hidden_div').find('div#the_other_div');
sourceDiv.insertAfter('div#the_other_div');

Edit: Updated to reflect Nick's valid comments.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜