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.
精彩评论