I want to remove the requeriment of jQuery in my app and I have this piece of code that handles an event related to a element.
So the original code is:
$(window.document).on('contextmenu', '.main td.active', function(e) {
$("#context-menu").hide().css({
left: e.pageX,
top: e.pageY
}).show();
e.preventDefault();
});
The migration is the following:
window.document.addEventListener('contextmenu', function(e) {
var el = document.getElementById("context-menu").style;
el.left = e.pageX,
el.top = e.pageY,
el.display = 'block';
e.preventDefault();
});
The problem is that the event (onContextmenu) is associated just only to the document.body ... then, when is fired, the event.target (mouse right-click) is checked to verify if matches with a .main td.active, instead of associate an event to each element.
(do not confuse with querySelector('.main td.active').addEventListener )
Any idea? Thanks!!