473,796 Members | 2,867 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How can I use onmouseover to change text color

110 New Member
I want the text to change from gray to bright red when the mouse is moved over the name of our company. Here is the code that doesn't work. What do I need to change to make this work?

Expand|Select|Wrap|Line Numbers
  1. function mouseOver(){
  2.     document.getElementById('unitedBrokers').style.font="size='2' face='Arial color='#FF0000'";
  3. }// mouseOver()
  4.  
  5. function mouseOut(){
  6.     document.getElementById('unitedBrokers').style.font="size='2' face='Arial color='#808080'";
  7. }// mouseOut()
  8.  
  9. <a id="unitedBrokers" onmouseover="mouseOver()" onmouseout="mouseOut()" style="text-decoration: none">United Brokers Incorporated</a>
  10.  
Feb 17 '09
19 16146
Dormilich
8,658 Recognized Expert Moderator Expert
you are using Internet Explorer?

then you need the cross browser workaround addEvent() (there are different versions available, search via google and choose the one you like)

if you call mouseOver() not by Event Handler, "this" refers to the actual scope which is the window object and thus has no style property.
Feb 19 '09 #11
andersond
110 New Member
I still haven't been able to successfully get text to change colors when the mouse rolls over it. Here's what's not working now:

Expand|Select|Wrap|Line Numbers
  1. function turnRed(){
  2.         document.getElementById('unitedBrokers').style.font.fontcolor="#FF0000";
  3. }
  4. function turnGray(){
  5.         document.getElementById('unitedBrokers').style.font.fontColor="#808080";
  6. }
  7.     <a href="Jsvascript:void(0);"
  8.     onmouseover="return turnRed();"
  9.     onmouseout="return turnGray();"
  10.     id="unitedBrokers" style="text-decoration: none" /><font color="#808080">United Brokers, Incorporated.</font></a>
  11.  
I do get a different cursor (finger instead of i-beam) but there is no change in the text color. This seems like it should be extremely simple; but, I just can't get it to work.
Feb 25 '09 #12
acoder
16,027 Recognized Expert Moderator MVP
The syntax is incorrect. What you need to set is style.color:
Expand|Select|Wrap|Line Numbers
  1. function turnRed(){
  2.     document.getElementById('unitedBrokers').style.color="#FF0000";
  3. }
See link.

PS. threads merged.
Feb 25 '09 #13
andersond
110 New Member
I made that change and it still does absolutely nothing. This is IE. That's all any of my agents use; so, if there is some change that needs to be made to use it in IE I need to know what those changes are.
Feb 25 '09 #14
acoder
16,027 Recognized Expert Moderator MVP
Yes, two more problems:
1. "Jsvascript " is an invalid protocol. Either use "javascript :" or just use "#" or a valid URL as long as you return false onclick.

2. Remove the font declaration within the link.

Having said that, this could be done without using JavaScript.
Feb 25 '09 #15
Provision
5 New Member
You're looking at this in too much of a complex angle, it's just simple and you don't need so much code.
Mar 13 '14 #16
Provision
5 New Member
Expand|Select|Wrap|Line Numbers
  1. <script>
  2. function turnRed(x)
  3. {
  4. unitedBrokers.style.color ="#ff0000";
  5. }
  6. </script>
  7. <script>
  8. function turnGrey(x)
  9. {
  10. unitedBrokers.style.color ="#808080";
  11. }
  12. </script>
  13.  
  14. <a id="unitedBrokers" onmouseover="turnRed()" onmouseout="turnGrey()" style="text-decoration: none">United Brokers Incorporated</a>
I've just tested this and it works
Mar 13 '14 #17
Dormilich
8,658 Recognized Expert Moderator Expert
still, the CSS solution doesn‘t even require JS:
Expand|Select|Wrap|Line Numbers
  1. <a class="color-swap">…</a>
Expand|Select|Wrap|Line Numbers
  1. .color-swap {
  2.   color: #888;
  3. }
  4. .color-swap:hover {
  5.   color: #f00;
  6. }
Mar 13 '14 #18
Provision
5 New Member
It still works, like he planned
Mar 13 '14 #19
Dormilich
8,658 Recognized Expert Moderator Expert
even after 5 years …
Mar 13 '14 #20

Sign in to post your reply or Sign up for a free account.

Similar topics

4
17114
by: Tim | last post by:
Hope someone in the big wide world can help... What I want to do is have an image slideshow which automatically scrolls through a series of images very fast, then pauses when you move your mouse over the image. The images will flick through (at a rate of about 5 per second) then pause when the user onMouseOver's. Any help would be gratefully received. :o)
5
10901
by: CQMMAN | last post by:
Hello, I am trying to change a piece of text using onmouseover. I have tried a few things so far and nothing has really worked. I get get a new piece of text to appear but bastardizing someone elses code, but can't figure out how to hide the other one.... I sort of have the following but don't know if this is close to the best way of doing it really...
7
2279
by: Richard | last post by:
I know I can have like <a href="#" onclick="dothis" onmouseover="dothat"> But how do you properly code two mouseover's in one statement? <a href="#" onmousever="dothis" onmouseover="dothat"> As an example of use: Column A holds menu items. When a mouse over is performed, two actions take place instead of one. Action one sends an image to a division in column B, action two sends text to another division in column B.
12
12291
by: Epetruk | last post by:
Hi all, I want a page where the contents of a table cell are replaced with an image when the mouse moves over the cell, and the text is restored when the mouse moves out. Here's the html for the page: <HTML> <HEAD> <style type="text/css">
5
3511
by: Martin Chen | last post by:
I have a frame set (as per MS FrontPage 2000). It has a contents and a main frame. The contents frame has a menu bar written with with javascript (in the context of a table). In IE6.1 everything works fine as it also does in firefox if I call the contents frame directly (i.e. outside of its frameset). However, if I call my main page (index.html) which invokes the frame set, the contents frame javascript menubar onmouseover function...
3
3947
by: drjackk | last post by:
Hello, I'm trying to change the onmouseover event dynamically. This sets-up the initial onmouseover event: <a href="home.html"> <img border="0" id="img22" src="images/home1.jpg" height="15" width="85" alt="Home" onmouseover="FP_swapImg(1,0,/*id*/'img22',/*url*/'images/home2.jpg')"</a>
4
2135
by: Rob R. Ainscough | last post by:
I'm using .NET v1.1 with ASPX web page. I'm trying to have a RollOver hyperlink that will change images on an image control and update the text in a Label control. I've got the image swapping working, however I don't know how to get my Label control text to change with the onMouseOver event HTML... </asp:hyperlink><asp:hyperlink id="lnkImageS" style="Z-INDEX: 113; LEFT:
3
5876
by: Vear | last post by:
Hi, I'm looking to change the cssclass on a hyperlink with the onmouseover. I've tried the 3 syntax's below but to no success. Can someone point me in the right direction. Thanks HyperLink1.Attributes.Add("onmouseover", "this.ClassName='hover'") HyperLink1.Attributes.Add("onmouseover", "this.CssClass='hover'") HyperLink1.Attributes.Add("onmouseover", "this.Class='hover'")
1
18854
by: den2005 | last post by:
Hi everybody, I am confused and still looking why this codes is not working. Can anyone notice or know why this code is not working? Thanks in advance. Code working: <form id="form1" runat="server"> <div> &nbsp;</div> <div>
0
10467
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10201
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10021
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9061
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7558
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6802
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5454
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4130
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3744
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.