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

Solving the problem of invalid onmouseover event of div

黄舟
Release: 2017-07-19 14:04:18
Original
3964 people have browsed it

I want to achieve the following functions: there is an 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>
Copy after login

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",".....");
     }
);
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template