How to get id like “invokedOn” text by a right cli

2019-07-03 14:05发布

问题:

I am using Bootstrap 3.0 ContextMenu. here is a link http://jsfiddle.net/KyleMit/X9tgY/

I need to know how i can get the id or data-Id of the clicked element. i try many of the tricks but i cant get the clicked element id? Like when i clicked on "Jacob" row i get the "Jacob" after clicked. I also need from this line
<td data-id="user-3"> <a data-id="user-3">Jacob<a/> <td/> "data-Id"?

i tried var $selectedFileId = $(this).closest('a').html(); or alert($(this).parent('a').html());

回答1:

Use this code for get clicked element id

jQuery(document).on('click', function(e){
console.log(e.target.id);
})


回答2:

I get the id by little additions in the contextMenu handler, Changes

// click handler for context menu
function ContextMenuClickHandler() {
    $(settings.menuSelector)
     .off('click')
     .on('click', function (e) {
      $(this).hide();

       var $invokedOn = $(this).data("invokedOn");
       var $selectedMenu = $(e.target);
       // My Changes
       var $selectedFileId = $(this).data("invokedOn").find('.yourClass').attr('id');

       settings.menuSelected.call($(this), $invokedOn, $selectedMenu, $selectedFileId);
    });
}