1

I want to get my <li> element that when i right-click on it: a customized contextual menu appears, and i want to do my treatment over my initially selected element <li>. I've tried this $(this).attr("id"); but it returns an item of my contextual menu and not my original right-clicked <li>.

Saf
  • 227
  • 3
  • 11
  • 1
    Take a look at http://stackoverflow.com/questions/1206203/how-to-distinguish-between-left-and-right-mouse-click-with-jquery There's also http://stackoverflow.com/questions/4235426/how-can-i-capture-the-right-click-event-in-javascript for plain javascript. – Raekye Dec 09 '12 at 02:04
  • Does seem to work for me -> [**FIDDLE**](http://jsfiddle.net/ASwjf/1/) – adeneo Dec 09 '12 at 02:04

1 Answers1

7

To detect right click you can use,

jquery code

<script language="javascript" type="text/javascript">
    $(function(){
        $('#rClick').on('contextmenu', function(e) {
            alert($(this).attr('id'));
            return false;
        });
    });
</script>

html code

<ul>
<li id="rClick">AAAAAA</li>
<li id="rClick2">BBBBBB</li>
</ul>
Swarne27
  • 5,521
  • 7
  • 26
  • 41
  • I think i didn't pass my message very well, When i use `$('#rClick').on('contextmenu', function(e) { alert($(this).attr('id')); return false; });` it return the id of the `
      ` _in my case_, i want exactely to get the id of the rightclicked `` inside that `
        `
    – Saf Dec 09 '12 at 13:22
  • 1
    can u post your code, then we can see what's the issue in it. the code which i have posted is working correctly and it returns which
  • element is rightclicked.
  • – Swarne27 Dec 09 '12 at 14:11