开发者

adding content using .html() method:-- but lost the clicked content ie"this"

开发者 https://www.devze.com 2022-12-15 16:16 出处:网络
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:

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());
});
0

精彩评论

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