Home  >  Article  >  Web Front-end  >  Solving the problem of invalid onmouseover event of div

Solving the problem of invalid onmouseover event of div

黄舟
黄舟Original
2017-07-19 14:04:183927browse

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

$(&#39;#divId&#39;).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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn