I'm doing a drag and drop thing. When the user grabs the element I need to add an event listener for dragenter
to every element. In that listener function I need it to get and save the clientX
when the mouse moves over that element. The issue I'm having is it gets the mouse position of the first element and keeps the same one for every other element. How can I fix this?
Code:
if(editor_children[i].nodeType != 3)
{
editor_children[i].addEventListener("dragenter", function(event){
if(event.target.id !== e.target.id) event.target.className= event.target.className + " highlight";
position= event.clientX;
last_over= event.target.id;
console.log("Mouse: " + e.clientX + " Position: " + position + " Last Element: " + last_over);
})
editor_children[i].addEventListener("dragleave", function(event){
event.target.className= event.target.className.replace(' highlight', '');
});
}
Please no JS libraries.