javascript - How to check what was clicked in jquery? -
javascript - How to check what was clicked in jquery? -
i want check clicked on whole document , save info target variable.
i want create logic knowledge clicked target.
here sample code:
$(document).ready(function(){ console.log("document ready"); event = ""; previousevent = ""; function init() { event = ""; target = ""; } init(); function loop() { if(event==previousevent) {event="event_nothing"; } if(event!=previousevent&&event!="event_nothing") { console.log("event: " + event); // (...) logic (...) } previousevent = event; } loop = setinterval(loop,100); //events $(document).keydown(function(e){ var key = e.which; if(key == "37") event = "event_keypress_leftarrow"; else if(key == "38") event = "event_keypress_uparrow"; else if(key == "39") event = "event_keypress_rightarrow"; else if(key == "40") event = "event_keypress_downarrow"; else {event = "event_keypress_unbinded";} }); $(document).click(function(){ event = "event_keypress_click"; target = ???????; //for illustration element in canvas, or tag in html }); });
event has target property
$(document).click(function(e){ event = "event_keypress_click"; target = e.target; });
javascript jquery
Comments
Post a Comment