How to execute a function after the contextmenu appears?

Asked

Viewed 48 times

0

I made a method to remove a class from my div when the contextMenu is called:

minhaDiv.oncontextmenu = function () {
    this.classList.remove("classe");
}

How can I make this class appear again soon after that the context menu appears?

  • I don’t know if this is what you’re looking for because the question isn’t clear (maybe if the context improves), but this solves minhaDiv.classList.add("classe") ?

  • Opa Ugusto, that’s what I want, but I want it to run afterward that this method is executed

1 answer

0

I will leave here as I solved the problem, it is a gambiarra and is probably not the ideal solution, but it works.

First I took the element that was underneath this div (the div was covering this element). I’ll call it the image here.

imagem.onmouseover = function(){
    minhaDiv.classList.add("classe");
};

This event only happens after the div is already removed, that is, it will not happen if the context menu has not already been called. Then just the user pass the mouse on imagem that the class is readjusted.

It was only possible to solve it this way because the class contained the information of size of the div, then the div basically disappeared without it.

  • 1

    I had even understood something after the comment. He implied that it was a case of using microtask I came to create an example https://repl.it/repls/PotableZigzagPort . But after I carefully read that answer I’m sorry but I can’t understand anything, an image appeared that was not in the question. I am obliged to negative question and answer because the question has no information about the real problematic and answer deals with something that is only on your computer.

  • What I want is simple. Have a div on my site. I want the div to be deleted and the normal context to appear when you rightclick it. After the context menu appears, simply put back the div

  • Maybe I couldn’t express myself well, but basically that’s it. Thank you anyway :)

  • On the question was about removing and reconditioning classes, now turned to remove and recondition Divs, appeared a contexmenu that was not in the question, the answer image. I’ve lost an hour of my life to a question that doesn’t stop changing.

  • I removed the classes, not the Divs.

  • And the context menu was yes on the question, just read, lol

Show 1 more comment

Browser other questions tagged

You are not signed in. Login or sign up in order to post.