How to get id like “invokedOn” text by a right click event with Bootstrap ContextMenu?

纵饮孤独 提交于 2019-12-12 12:26:40

问题


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);
    });
}  


来源:https://stackoverflow.com/questions/26110254/how-to-get-id-like-invokedon-text-by-a-right-click-event-with-bootstrap-contex

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!