I'm trying to add a marker and a div next to the mouse click in vanilla Javascript.
Basically if the user clicks anywhere on the page, I want to add a marker where the click was made (a circular small div) and show a div next to the marker.
If the user presses somewhere else, the previous marker and div disappears and they basically appear in the new location of the click
- What I did:
- I created the div and I set the display to none, and now I'll try to make it appear when the user clicks anywhere on the page
- for the marker, I have this Jquery code that I will convert to vanilla JS:
$(function(){
$('body').click(function(e){
var x = e.clientX;
var y = e.clientY;
var circle=$('<div class="circle"></div>');
circle.css('top',e.pageY - 15);
circle.css('left',e.pageX - 15)
$('body').append(circle);
})
})