0

I'm trying to detect a left click on the contextual menu to no avail, my script should update a div on change, keyup or copy from the contextual menu in a textarea. This is what I've tried:

$("#keywords").bind("click keyup change", function(){}
$("#keywords").bind("contextmenu keyup change", function(){}

Both the codes above need an extra click on the page to fill the DIV.

Is there any solution to this?

Thx

9
  • Also, developer.mozilla.org/en-US/docs/Web/API/Event/preventDefault might be a key-word to search a helpful information, if I were you. Commented Jul 28, 2018 at 3:30
  • @KenOKABE, that just won't work because it prevents the contextual menu from opening, I want it to open and the user to left click on "paste" and the DIV should update after that last click. Sorry if I'm missing something, I'm a beginner trying to learn by working on a project. Commented Jul 28, 2018 at 3:36
  • Pretty sure it's impossible stackoverflow.com/questions/9305220/… Commented Jul 28, 2018 at 3:52
  • Fair, is there a way to detect right click followed by left click and firing the code after the second click? Commented Jul 28, 2018 at 3:56
  • 1
    What is it that you really want to do? This is clearly a XY problem. Maybe you are actually just looking to use the "input" event rather than "keyup"? Commented Jul 28, 2018 at 4:20

2 Answers 2

0

You cannot detect anything regarding the context menu since this happens outside the context of the page itself.

You can either use the paste event, see here, or, if you just want to track any kind of changes to the textarea, just use the input event:

$("#keywords").on("input", function() { ...};
Sign up to request clarification or add additional context in comments.

Comments

-1

Not clear enough. Try something like:

$(document).on('change keyup', '#keywords', function(e){
   //Do something when typing/changed like update the div html
  $('.my-div').html($(e.target).val());
});

3 Comments

The keyup part is working, my concern is the left click on contextual menu. You have to right click to open it an then left click to click on "paste" and it's that part that I want to trigger. Thank you for your help.
I think there isn't away to detect a left click on the contextual menu. I would prevent it from opening and create a custom one instead.
Ok thank you. Is there a way to detect right click followed by left click and firing the code after the second click?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.