2

I'm currently trying to clone with the following code:

var position = $(this).position();
var ptop = position.top;
var pleft = position.left;
$(this).click(function() {
                $(this).clone().css({
                    top: ptop,
                    left: pleft,
                    opacity: '0.55'
                })
}).appendTo(this);

I need the element to clone at the exact position than the brother element. Thats why I have:

    var position = $(this).position();
    var ptop = position.top;
    var pleft = position.left;

For getting the position. But I also what the clone to have a lighter opacity.

Adam Rackis
  • 82,527
  • 56
  • 270
  • 393
Shawn31313
  • 5,978
  • 4
  • 38
  • 80

1 Answers1

6

You've got your parentheses messed up. Your call to "appendTo()" is being applied after the establishment of the "click" handler.

$(this).click(function() {
                $(this).clone().css({
                    top: ptop,
                    left: pleft,
                    opacity: '0.55'
                }).appendTo(this);
});

You need it inside the "click" handler, and it needs to be called on the ".clone()" return value.

Pointy
  • 405,095
  • 59
  • 585
  • 614