Jump to content

Javascript Question


Guest savmoy

Recommended Posts

Guest savmoy

Hi!I have used the example in the W3Schools tutorials on onMouseOver() and onMouseOut() to come up with a piece of code that I want to use to change the color of my document title when I move over the title to blue, and then to red when I move away from the title. But somehow it is not working. Can you please tell me what I am doing wrong. Thank you in advance for the response!Here is my JavaScript code:<html><head><script type="text/javascript">function mouseOver(){document.getElementById("mytitle").style ="color:blue";}function mouseOut(){document.getElementById("mytitle").style ="color:red";}</script></head><body><h1 align="center" id="mytitle" onMouseOver="mouseOver()" onMouseOut="mouseOut()">MY TITLE</h1></body></html>

Link to comment
Share on other sites

hi,Use this code and check. hope it will work fine.<html><head><script type="text/javascript">function mouseOver(){document.getElementById("mytitle").style.color ="blue";}function mouseOut(){document.getElementById("mytitle").style.color ="red";}</script></head><body><h1 align="center" id="mytitle" onMouseOver="mouseOver()" onMouseOut="mouseOut()">MY TITLE</h1></body></html>

Link to comment
Share on other sites

In Firefox the error I get with the original code is "setting a property that only has a getter" for lines 6 and 10. This code also works:

<html>	<head>		<script type="text/javascript">		function mouseOver()		{			var x = document.getElementById("mytitle"); 			x.style.color = "blue";		}/*Creates a variable named 'x' and sets it equal to whatever you want. The next line styles the element.*/		function mouseOut()		{			var x = document.getElementById("mytitle");			x.style.color = "red";		}/*Same as above function.*/		</script>	</head>	<body>		<h1 align="center" id="mytitle" onMouseOver="mouseOver()" onMouseOut="mouseOut()">MY TITLE</h1>	</body></html>

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...