views:

37

answers:

2

I have table which contains the rows that are dynamic from server side scripting(PHP) and also using Zend Framework . So each row will have hyperlink with id SOmevalue(Dynamic) now each row will have contextmenu (Jquery Plugin ) appended to each row by the below code.

    $("#myTable td:first-child").contextMenu("myMenu1",{
      bindings: {
            'hdr': function(t) {
                alert($("#Test0").attr("data-value1"));
                alert($("#Test0").attr("data-value2"));

             }
      },
      menuStyle: {
            border: '1px solid #000'
       }
      });

So My Problem is how do i know on which row was context menu clicked and suppose if i click on second row i want to get the value of that < a href> value of that "test1" or "test2" or "test3" or "test4"
dynamically . i should not able to write "test1"or test2 son on

+2  A: 

AS with most jQuery event handlers, my guess is that the this variable will be the element that was clicked. Regardless, if you can at least get the element that was clicked, the rest should be easy.

Check out the closest()method in the API docs: http://api.jquery.com/closest/

I'm just guessing here, but you could do something like
var value = $(this).closest("a.someClass").attr("data-value1"); where "someClass" is optional but would help to make sure you got the right anchor tag if there were potentially others in the same row.

Eric
+1  A: 

Please provide the html markup that gets generated. Something along these lines should work:

$("#myTable td:first-child").contextMenu("myMenu1", {
    bindings: {
        'hdr': function(t) {
            alert($("this").closest("tr").find("a").attr("href"));
        }
    },
    menuStyle: {
        border: '1px solid #000'
    }
});
Floyd Pink