Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Adds image anywhere on a webpage at every location someone clicks.
function createImage(coordinates){
var xPos = coordinates[0];
var yPos = coordinates[1];
var image = document.createElement("img");
image.src = ;// add image file reference here
// set their position = yPos + "px"; = xPos + "px";
image.draggable = false; // this really should be done in CSS
console.log(xPos + yPos);
function getCursorPosition(){
var x = event.clientX; // Get the horizontal coordinate
var y = event.clientY; // get the vertical coordinate
var coordinates = [x,y];
return coordinates;
function removeText(text){ = "none";
function main(){
var clickText = document.getElementById("clickText"); // get rid of the thing that says to click anywhere
var coordinates = getCursorPosition();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment