tuyenle tuyenle - 7 months ago 34
jQuery Question

duplicate image when click so it follow the cursor Jquery

I want to be able to duplicate an image when clicking on it then making it follow the cursor while retaining the original image's position. This code works when clicking on an image so that it follow the cursor but with the original image. I want to duplicate it

$('li').on("click", function (e) {

// Make image follow cursor upon clicking
if ($(this).get(0).classList.toString().search("-") > -1) {

var $canvas = $(this).get(0).classList.toString().split(" ").join(".");

$('ul,.map').mousemove(function (e) {
$('.' + $canvas).offset({left: e.pageX, top: e.pageY});

I don't know which method to use to duplicate an image. I try using


like so

$('.' + $canvas).clone().offset({left: e.pageX, top: e.pageY})

but it didn't work.


This would clone all p elements and append to the body. It was taken from W3C jQuery clone() Method page. It looks like it didn't work because the syntax in your clone method was wrong. Maybe try something like


Here is the link to W3C schools entry for clone method - http://www.w3schools.com/jquery/html_clone.asp