Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Capture Right Click on HTML DIV

I am trying to paint cell on a html page, where each cell is a DIV, I need to be able to capture right click event on any of these cells, How can I do that?

<script>
function fn(event)
{
 alert('hello'+event.button);
}
</script>

<div id="cell01"
         class=""
         onclick="fn(event);"
         style="left: 1471px; width: 24px; height: 14px; top: 64px; text-align: center; position: absolute; background-color: rgb(128, 128, 0);">1</div>
like image 634
sachin Avatar asked Jul 07 '09 15:07

sachin


1 Answers

the easiest way

<div style="height: 100px; background-color: red;" oncontextmenu="window.alert('test');return false;"></div>
like image 82
Pawel Avatar answered Sep 24 '22 23:09

Pawel