Hi Dan,

Many thanks for the reply, thats been a great help.  Finally got it
working!

Heres some sample code for anyone else interested.

Regards, Ben.

<script language="javascript" charset="utf-8">
    $(document).ready(function() {

         $('span.demo1').contextMenu('myMenu1', {
                  bindings: {
                        '1': function (trigger, target){
                          alert('Trigger was '+t.id+'\nAction was Open');
                        },
                        '2': function(t) {
                          alert('Trigger was '+t.id+'\nAction was Email');
                        },
                        '3': function(t) {
                          alert('Trigger was '+t.id+'\nAction was Save');
                        },
                        '4': function(t) {
                          alert('Trigger was '+t.id+'\nAction was Delete');
                        }
                  }
                });

});


</script>
<div class="contextMenu" id="myMenu1">
  <ul>
    <li id="1"><a href="#">Test 1</a></li>
    <li id="2"><a href="#">Test 2</a></li>
    <li id="3"><a href="#">Test 3</a></li>
    <li id="4"><a href="#">Test 4</a></li>
  </ul>
</div>

<p> <span class="demo1" id="demo1_yellow"><b>RIGHT CLICK FOR DEMO</b></
span>

<span class="demo1" id="demo1_green1" style="background-
color:lightgreen"><b>THIS WORKS TOO</b></span>

<span class="demo1" id="demo1_green2" style="background-
color:lightgreen"><b>THIS WORKS TOO</b></span>
<span class="demo1" id="demo1_green3" style="background-
color:lightgreen"><b>THIS WORKS TOO</b></span>
<span class="demo1" id="demo1_green4" style="background-
color:lightgreen"><b>THIS WORKS TOO</b></span>
<span class="demo1" id="demo1_green5" style="background-
color:lightgreen"><b>THIS WORKS TOO</b></span>
<span class="demo1" id="demo1_green6" style="background-
color:lightgreen"><b>THIS WORKS TOO</b></span>


On Mar 3, 2:55 pm, "Dan G. Switzer, II" <[EMAIL PROTECTED]>
wrote:
> Benster,
>
>
>
> >Im new to jquery and im struggling with hopefully a simple question!
>
> >Im using theContextMenuplugin-
> >http://www.trendskitchens.co.nz/jquery/contextmenu/
> >which allows you to generate a right-clickmenu.  All works fine,
> >however im now trying to pass in the id of the item that has been
> >clicked upon.
>
> >Im listing several images on a page, and offering the right-clickmenu
> >for each.  I need to pass in the id of the image which has been
> >clicked.  Each image has a div with a unique id.
>
> >The documentation mentions "bindings" which i think is what im after,
> >but have no idea how to display the function pairs.  Here is the
> >description from the docs -
>
> >An object containing "id":function pairs. The supplied function is the
> >action to be performed when the associated item is clicked. The
> >element that triggered the currentmenuis passed to this handler as
> >the first parameter.
>
> >Can anyone advise me on how to proceed?
>
> It's been a while since I've used that plug-in for a project, but it is the
> "bindings" option you're looking for:
>
> $("#attachTo").contextMenu("#menuDiv", {
>         bindings : {
>                 "a.cm_item" : function (trigger, target){
>                         // "trigger" is the "#attachTo" element
>                         console.log(trigger);
>                         // "target" should be the "a.cm_item" element
>                         console.log(target);
>                 }
>         }
>
> });
>
> The above should attach a click event to every <a class="cm_item" /> tag
> found in thecontextmenu. The "target" argument should be a reference to
> this DOM element.
>
> -Dan

Reply via email to