Note that there are some explanatory texts on larger screens.

plurals
  1. POgetting an element id from a plain javascript call
    text
    copied!<p>This example is simplified a bit, but in my ASP.NET web page in my c#/jquery code I am using a right hand context menu that displays ‘rightMenu’ when a right mouse is clicked.</p> <pre><code>$(document).ready(function() { $(".RH_signoffrow td").contextMenu({ menu: 'rightMenu' }, function(action, el, pos) { var mykey = getkeyforitem(el); mykey = "Details|" + mykey; alert( 'Action: ' + action + '\n\n' + 'Key is: ' + mykey ); if(action == "details"){ trigger_details_panel(mykey); } }); }; //for any td in the right hand side - get its row key function getkeyforitem(el){ var mykey = $(el).parent().find('.hiddenrowkey').text(); // alert( // 'Internal getkeyforitem Call' + '\n\n' + // 'Key is: ' + mykey // ); return mykey; }; </code></pre> <p>The callback of the menu passes back the element that was clicked, and that can be used to pull the keydata out of the current table row. Once I have that keydata, I can use it to call the real function I was after: trigger_details_panel(mykey).</p> <p>This works fine if I only want to use the right mouse, but I want to include an image in some of the rows, so that when the image is clicked, it produces the same effect,as the right mouse menu selection.</p> <p>I am not sure how to accomplish that cleanly.</p> <p>I can include an image that links to javascript in my page…</p> <pre><code> &lt;asp:ImageButton ID="imgDetails" runat="server" ToolTip="Show Details" ImageUrl="./images/details.gif" OnClientClick="showdetailsclicked();return false;"&gt;&lt;/asp:ImageButton&gt; </code></pre> <p>But how can I get it to call the code: </p> <pre><code>getkeyforitem(el); </code></pre> <p>Or at least know the element (el) it belongs to? It seems like there should be a way to use the (this) pointer to get at what I want - but I don't see it. Am I just missing a more straightforward way to accomplish the whole problem?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload