Disabling rightclick…but enabling it on other places?

30 views
Skip to first unread message

Kevin Ingwersen

unread,
Aug 25, 2013, 9:06:06 PM8/25/13
to appj...@googlegroups.com
Hey everyone.

Quick question, lets get into the code:

<html<
<head>...</head>
<body onrightclick="return false;">
<div id="content">blablabla</div>
<div id="console">[prog/cmd] msg</div>
</body>
</html>

I want to make right-click in #console work. I have a way bigger structure with more divs. So basically, I want to enable rightclick just in one div, but disable it everywhere else. o.o
How's that gonna be done?
I do use jQuery.

Regards, Ingwie

sihorton

unread,
Aug 29, 2013, 12:21:21 PM8/29/13
to appj...@googlegroups.com, ingwi...@googlemail.com
Hi Ingwie :-)

You should just be able to set multiple event handlers. So with jQuery bind to document or to a div somewhere and set what you want the right click to do in general. Then for the console div bind to that and set the right click for it. Since events "bubble" from one div to the next if there is no event handler then an event will be caught by the div closest to it. So the magic of jquery should mean you can program a generic handler at the document or root div handler and then program a handler for any div that you want to handle differently.

/Simon
Reply all
Reply to author
Forward
0 new messages