Prioritize onclick event

Asked

Viewed 45 times

0

Good afternoon,

I have a table that has an event by clicking on tr and td. I need to place a text field inside the td with an event by clicking as well. When I do this the events of tr and td are prioritized and the text field event does not work. How do I force the onclick event from the text field?

Thank you

  • Guy puts his code there, html/js without them makes it hard to answer you!

1 answer

0


Put this in the text field to prevent propagation of relatives' events. More information here

document.querySelector('.seuInput').addEventListener("click", e => {
    e.stopPropagation();
})
  • 1

    But what if the tr have other child elements that should be clickable? It is easier to treat this problem by putting a stopPropagation in the text field.

  • Really, I agree with you, I changed the answer

  • Thank you very much. It worked perfectly

Browser other questions tagged

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