Hi I want to remove a div in jQuery. This is my code but I have test and doesn’t work, the div doesn’t remove. help me.
var img_old=$(".colCenter").find('#div_'+old_id);
img_old.delay(10).animate({top:1440},1500, function(){
img_old.remove();
});
This is the html
<div class="colCenter" id="two">
<div id="randomdiv" style="display:none;"></div>
<div class="content" id="div_index">
<div class="img_background">
<img src="img/sfondi/index.jpg" alt="" class="old_img" id="img_index"/>
</div>
<div class="logo_home">
<a href="index.php"><img src="img/logo_grande.png" alt="Web & Design" title="Web & Design" /></a>
</div>
</div>
</div>
http://jsfiddle.net/mblase75/FJchB/ — your code works fine for me.
Perhaps the variable
old_idisn’t set in your code? I had to set it to “index” to get anything to happen.As others have suggested, you also need to wrap your code in a
$(document).ready{...}block so it only runs after the elements are loaded.