I want to delete a jQuery query in my application, and I have this piece of code that handles the event associated with the element.
So, the source code:
$(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 as follows:
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 only associated with document.body ... then when it is fired, event.target (right-click) checks if matches match .main td.active, and not bind the event to every element.
(do not confuse with querySelector ('. main td.active'). addEventListener)
Any idea? Thanks!!
source
share