In the absence of the parent div, the child div is printed as follows
Mouseover:
- Div1,
- Div2, div1,
- Div1,
- Div2, div1
The child div is triggered first
Mouseenter:
- div2
- div2
- div2
Div1 does not trigger
The test code
<! DOCTYPEhtml>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="Width = device - width, initial - scale = 1.0">
<title>Document</title>
<style>
.div1 {
width: 200px;
height: 200px;
background-color: aqua;
position: relative;
left: 0;
}
.div2 {
width: 100px;
height: 100px;
background-color: red;
position: absolute;
left: 200px;
}
</style>
</head>
<body>
<div class="div1">
<div class="div2"></div>
</div>
<script>
const div1 = document.getElementsByClassName("div1") [0]
const div2 = document.getElementsByClassName("div2") [0]
div1.addEventListener("mouseenter".function () {
console.log("div1")
})
div2.addEventListener("mouseenter".function () {
console.log("div2")})</script>
</body>
</html>
Copy the code