用innerHTML鼠标悬停在图像上

时间:2015-02-12 00:11:28

标签: javascript jquery html image mouseover

我需要在图像被鼠标悬停时将其交换出来。它应该使用innerHTML我也相信。

<body>

<a href="#">anime</a>
<a href="#">ponies</a>
<h1 class="panel">What fandom is better?</h1>
<div class="anime"> <img src="img/anime.png"> </div>
<div class="pony">  <img src="img/pony.png"> </div>
<p id="answer">Choose One</p>
</body>
/**
 This is for element changes upon mousesing over of the area
 */` 
document.getElementsByClassName("anime")[0].onmouseover=
    function(){
        orangeBorder1();
        mouseAnime();
    }

document.getElementsByClassName("pony")[0].onmouseover=
    function(){
        orangeBorder();
        mousePony();
    }
function mousePony(){
    document.getElementById("pony").src="pony1.png";
}

1 个答案:

答案 0 :(得分:0)

我不知道您的代码是否被错误复制,但您没有任何ID为小马的内容

getElementById将查找属性为id的标记,指定该标记并且您的代码应该有效。

id在页面中应该是唯一的。你也应该给div一个id而不是查询classname