adding content using .html() method:-- but lost the clicked content ie"this"
I want to copy a content from one div when clicked and write it to other div:
But whe开发者_如何学Cn doing this I lost the clicked content from first div:
$(img).click(function(){
var newdiv=this;
$(".second").html(newdiv);
});
I have two divs with class first and second. First div having images.
Why did I lose the first div's content or the click element, ie "this"?
I think you want:
$(".first").click(function(){
var newdiv=$(this).html();
$(".second").html(newdiv);
})
Edit (thanks gnarf!)
I'm assuming that you want to put any .first img
inside of .second
when it is clicked on:
$('.first img').click(function() {
var $this = $(this);
$('.second').empty().append($this.clone());
});
精彩评论