Jump to content

Javascript Question


Guest savmoy
 Share

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>

Edited by AAA
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...