JavaScript help

mouseover and onclick

Page 1 of 1

5 Replies - 1026 Views - Last Post: 05 December 2010 - 07:20 PM

#1 sammy123   User is offline

  • D.I.C Head

Reputation: -3
  • View blog
  • Posts: 86
  • Joined: 23-October 10

JavaScript help

Posted 05 December 2010 - 09:27 AM

Right I am after some pointers on how to do the following using Javascript with XHTML. The first is that I must include a link that when clicked changes the color of my text on my homepage. The second is to use a mouseover command that enlarges the image when i user has the mouse over that particular image.

I would appreciate any help people could give me.
Is This A Good Question/Topic? 0
  • +

Replies To: JavaScript help

#2 sammy123   User is offline

  • D.I.C Head

Reputation: -3
  • View blog
  • Posts: 86
  • Joined: 23-October 10

Re: JavaScript help

Posted 05 December 2010 - 10:46 AM

this is the code I am trying to change the colour of text.

<script type="text/javascript">
function setColor()
{
document.getElementByClass("content").style.color="#9999";

}
</script>
<input type="button" onclick="setColor()"
value="Change color of text" />



Was This Post Helpful? 0
  • +
  • -

#3 Dormilich   User is offline

  • 痛覚残留
  • member icon

Reputation: 4202
  • View blog
  • Posts: 13,275
  • Joined: 08-June 10

Re: JavaScript help

Posted 05 December 2010 - 01:01 PM

there is no method called getElementByClass() (the error console would have told you that), only getElementsByClassName() (which is not supported by every browser).

better give your content element the appropriate ID and use getElementById().
Was This Post Helpful? 0
  • +
  • -

#4 sammy123   User is offline

  • D.I.C Head

Reputation: -3
  • View blog
  • Posts: 86
  • Joined: 23-October 10

Re: JavaScript help

Posted 05 December 2010 - 03:56 PM

Right I have a id named .content which using the javascript should change the color to #9999 but when I click on it it says error on page.

This post has been edited by sammy123: 05 December 2010 - 04:00 PM

Was This Post Helpful? 0
  • +
  • -

#5 sammy123   User is offline

  • D.I.C Head

Reputation: -3
  • View blog
  • Posts: 86
  • Joined: 23-October 10

Re: JavaScript help

Posted 05 December 2010 - 06:22 PM

<script type="text/javascript">
function setColor()
{
document.getElementById("content").style.color="#9999";
}
</script>
<input type="button" onclick="setColor()"
value="Change color of text" />


#content

		{
			
		width: 80%;
		float: left; 
		display: block;
 		padding: 5px 5px 5px 0.5em;
 		border-left: 1px solid #06F;
 		border-right: 1px solid #06F;
 		border-top: 1px solid #06F;
		border-bottom: 1px solid #06F;
 		background-color: #CCC;
 		color: #06F;
 		text-decoration: none; 
		margin-left: 2%;
		
		}

This post has been edited by Dormilich: 05 December 2010 - 11:25 PM
Reason for edit:: please use [code] /* your code source here */ [/code] tags when posting code

Was This Post Helpful? 0
  • +
  • -

#6 Atli   User is offline

  • Enhance Your Calm
  • member icon

Reputation: 4240
  • View blog
  • Posts: 7,216
  • Joined: 08-June 10

Re: JavaScript help

Posted 05 December 2010 - 07:20 PM

Where exactly is the element you've assigned the ID "content" to? It's not in the code you posted.

Also, you shouldn't use IE to test things. It's just... bad.
If you open this up in Firefox or Chrome (or any other decent browser) then you can see the error in more detail. (Press CTRL+SHIFT+J to open the error console in Fx or Chrome)

We need these details if we are to help you. Shockingly, the phrase "error on page" isn't exactly a big help when diagnosing an error.
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1