Home > Article > Web Front-end > Solving the problem of invalid onmouseover event of div
I want to achieve the following functions: there is an a1f02c36ba31691bcfe87b2722de723b in the div tag, and I want to change the image when the mouse passes over the div. My approach is to use the onmouseover event of the div: replace the innerHTML content of the div (replace it with a new
<!DOCTYPE html>
<head>
<meta charset="utf-8">
<title>test</title>
<style>
</style>
<script type="text/javascript">
function changeImg() {
var imageEle = document.getElementById("img");
imageEle.src = "2.jpg";
}
function changeImgAgain() {
var imageEle = document.getElementById("img");
imageEle.src = "1.jpg";
}
</script>
</head>
<body>
<div id="handler" onmouseover="changeImg()" onmouseout="changeImgAgain()" style="backgound: #333; width: 300px; height: 300px"></div>
<div><image id="img" src="1.jpg" /></div>
</body>Replace mouseout with mouseleave event.
There is no problem with the idea, please post your code, it is your code that has the problem
$('#divId').hover(
function() {//mouseover
$(this).find("image").attr("src","......");
},
fucntion(){//mouseout
$(this).find("image").attr("src",".....");
}
);The above is the detailed content of Solving the problem of invalid onmouseover event of div. For more information, please follow other related articles on the PHP Chinese website!