The example in this article describes javascript event bubbling. Share it with everyone for your reference. The specific analysis is as follows:
Event bubbling:
If element A is nested in element B, then when A is clicked, not only A's onclick event will be triggered, but B's onclick event will also be triggered,
The triggering sequence is "from inside to outside". Verification: add a table on the page, there is tr in the table, td in tr, and a p in td,
Add event response in p, td, tr, table
<html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>事件冒泡</title> </head> <body onclick="alert('body click');"> <table onclick="alert('table click');"> <tr onclick="alert('tr click');"> <td onclick="alert('td click');"> <input type="button" value="单击我" onclick="alert('button click');" /> </td> </tr> </table> </body> </html>
I hope this article will be helpful to everyone’s JavaScript programming design.