title: Javascript: Capture Id of right click element
body: <p>I have a piece of code that is working great, but it addresses only one Id (headline11). The problem is that I can have many Id's (headline11, headline12, headline13,...). I can get the Id of the right-clicked element see my fiddle here <a href="https://jsfiddle.net/yagami889/xpvt214o/471009/" rel="nofollow noreferrer">https://jsfiddle.net/yagami889/xpvt214o/471009/</a> but I can't make it work for my piece of code, I get a bunch of jQuery errors. This is what I'm trying to do to start with my testings:</p>
  
  <pre><code>var idHeadline = "";
  
  $('input').contextmenu(function() { 
              idHeadline = $(this).attr('id');
          });
  
  $("#" + idHeadline).on("contextmenu",function(e){
    e.preventDefault();
    $("#cntnr").css({"left": e.pageX-3, "top": e.pageY-3});
    $("#cntnr").fadeIn(200, startFocusOut);
  
  });
  
  function startFocusOut(){
    $("#cntnr").on("click",function(){
    $("#cntnr").hide();        
    $("#cntnr").off("click");
    });
  }
  
  $("#items &gt; li").click(function(){
  $("#" + idHeadline).val($(this).text().replace("fallback", " "));
  var input1 = $("#" + idHeadline);
  setInputSelection(input1, 9, 10);
  });
  </code></pre>
  
  <p>This is the working code:</p>
  
  <pre><code>$("#headline11").on("contextmenu",function(e){
    e.preventDefault();
    $("#cntnr").css({"left": e.pageX-3, "top": e.pageY-3});
    $("#cntnr").fadeIn(200, startFocusOut);
  
  });
  
  function startFocusOut(){
    $("#cntnr").on("click",function(){
    $("#cntnr").hide();        
    $("#cntnr").off("click");
    });
  }
  
  $("#items &gt; li").click(function(){
  $("#headline11").val($(this).text().replace("fallback", " "));
  var input1 = $("#headline11");
  setInputSelection(input1, 9, 10);
  });
  </code></pre>
  
  <p>Thank you for your help,</p>