views:

120

answers:

2

I used context menu plugin and was able to make if functional on the page I currently developing. At right click, I want to run a code (such as to highlight a selected row or column) before showing the context menu. Where can I insert the code. I used the plugin on this link. http://www.trendskitchens.co.nz/jquery/contextmenu/

My html:

<table>
  <tr><td></td><td></td></tr>
  <tr><td></td><td></td></tr>
  <tr><td></td><td></td></tr>
  <tr><td></td><td></td></tr>
<table>

My js (context menu)

$("table tr td").contextMenu('myMenu',{
     onContextMenu: function(e){
         // I want to process the selected 'td' or 'tr' here... ex. highlight it
     }
});
A: 

You can access the element that was right-clicked with e.target, e.g.:

$("table tr td").contextMenu('myMenu',{
    onContextMenu: function(e){
        $(e.target).effect("highlight", {}, 500);
    }
});

The highlight effect is part of jQueryUI.

piquadrat
A: 

You can use the following code to highlight the parent row

 $("table tr td").contextMenu('myMenu',{
 onContextMenu: function(e){   
     var parent=$(e.currentTarget).parent();
     parent.addClass('SelectedRowColor');
 }

where SelectedRowColor row is the css class name . hope that will help.

Asim Sajjad