I'm failing at the following since 2 hours. I'm trying to move the div id="msg" after the div class="meta anchor" when <i class="icon-delete delete"></i> is clicked. The whole thing has me in knots, because of the way it's structured.
I've marked where the div id="msg" should move to. Can you pls help? My failed efforts are below.
<div class="reQ">
<div class="post">
<div class="entry">
<div class="links">
<div class="icons"><i class="icon-delete delete"></i></div>
</div>
<div class="meta anchor">
Content
</div>
!-- div id="msg" goes here --!
</div>
</div>
</div>
<div id="msg">Div with Message</div>
jQuery
$('.delete').live('click', function() {
var self = $(this);
// $('#msg').insertAfter(self.parent()).show();
// self.parent().after('.msg');
self.parents('.reQ').$('#msg').insertAfter('.anchor').show();
});
Fiddle
Edit
The html part repeats several times on the page. It holds posts. I need the msg to go under only the post where the icon was clicked.
Try this
$('.delete').on('click', function() {
var anchor = $(this).closest('.post').find('.anchor');
$('#msg').insertAfter(anchor).show();
});
http://jsfiddle.net/dhR36/4/
Also you are using jquery 1.7 so you should change live to .on
Here is the doc on insertAfter http://api.jquery.com/insertafter/
Try this
Js
$(".icon-delete").click(function() {
$("#msg").insertAfter(".meta");
})
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With