I am using jQuery context menu plugin by Chris Domigan to appy a context menu. This is how I do it:
$('#contacts tbody tr').contextMenu('myMenu1', {
bindings: {
'copy': function(t) {
alert('Trigger was '+t.id+'\nAction was Copy');
},
'delete': function(t) {
alert('Trigger was '+t.id+'\nAction was Delete');
}
},
});
My question is, how do I get the content of the clicked tr item? I tried with
$(t.target).html()
but it returns null
. Any idea?
EDIT: here is the example /
I am using jQuery context menu plugin by Chris Domigan to appy a context menu. This is how I do it:
$('#contacts tbody tr').contextMenu('myMenu1', {
bindings: {
'copy': function(t) {
alert('Trigger was '+t.id+'\nAction was Copy');
},
'delete': function(t) {
alert('Trigger was '+t.id+'\nAction was Delete');
}
},
});
My question is, how do I get the content of the clicked tr item? I tried with
$(t.target).html()
but it returns null
. Any idea?
EDIT: here is the example http://jsfiddle.net/gqhRV/
Share Improve this question edited Jan 18, 2011 at 16:08 DarkLeafyGreen asked Jan 18, 2011 at 15:41 DarkLeafyGreenDarkLeafyGreen 70.4k135 gold badges390 silver badges614 bronze badges 7- 1 thats really vague please include your html, even better create a jsFiddle! – Amjad Masad Commented Jan 18, 2011 at 15:56
- show some HTML, I'm guessing you're doing something abnormal – hunter Commented Jan 18, 2011 at 16:07
- here is the example code jsfiddle.net/gqhRV – DarkLeafyGreen Commented Jan 18, 2011 at 16:08
- when I add an id to your tr tag, that's what value comes back in the copy popup. not quite what the documentation suggests. – Tom B Commented Jan 18, 2011 at 16:20
- why your link(plugin) is redirecting to a kitchen's site? – Chandan Kumar Thakur Commented Jul 13, 2019 at 12:17
2 Answers
Reset to default 9I think is this what you want:
<script type="text/javascript">
$(function(){
$.contextMenu({
selector: '.flexme1 tbody tr',
callback: function(key, options) {
alert("Clicked on " + key + " on element " + options.$trigger.attr('id').substr(3));
},
items: {
"edit": {name: "Edit", icon: "edit"},
"cut": {name: "Cut", icon: "cut"},
"copy": {name: "Copy", icon: "copy"},
"paste": {name: "Paste", icon: "paste"},
"delete": {name: "Delete", icon: "delete"},
"sep1": "---------",
"quit": {name: "Quit", icon: "quit"}
}
});
$('.flexme1 tbody tr').on('click', function(e){
console.log('clicked', this);
})
});
</script>
It's integrated with the Flexigrid... works fine for me...
And obviously i have some extra options.
not familiar with the plugin, but from the looks of it you should be able to write:
$("#" + t.id).html();
but in the case of most jQuery plugins you should be able to do this:
$(this).html();
from within the context of the 'copy': function(t) {
and 'delete': function(t) {
$('#contacts tbody tr').contextMenu('myMenu1', {
bindings: {
'open': function(t) { ShowAction(t, "Open"); },
'email': function(t) { ShowAction(t, "Email"); },
'save': function(t) { ShowAction(t, "Save"); },
'delete': function(t) { ShowAction(t, "Delete"); }
}
});
function ShowAction(t, a) {
alert('Trigger was ' + t.id + '\nAction was ' + a + "\nHtml is " + $(t).html());
}
Here's a working example: http://jsfiddle.net/dNUgg/
I'm guessing your <tr>
tags do not have an id
attribute
Even when the <tr>
does not have an ID this still works: http://jsfiddle.net/dNUgg/1/
alert('content is ' + $(t).text() + '\nAction was Delete');
updated your jsfiddle: http://jsfiddle.net/gqhRV/1/
you were doing $(t.target).text()
when you should be doing $(t).text()