Specialty Forums
Security and Virus
General Hardware
CPUs/Overclocking
Networking
Digital Photo/Video
Office Software
PC Gaming
Console Gaming
Programming
Database
Web Development
Digital Home

General Forums
Windows XP
Windows Vista
Windows 95/98
Windows Me
Windows NT
Windows 2000
Win Server 2008
Win Server 2003
Windows 3.1
Linux
PDAs
BeOS
Novell Netware
OpenVMS
Solaris
Disk Op. System
Unix
Mac
OS/2

Drivers
Driver Scan
Driver Forum

Software
Automatic Updates

BIOS Updates

My Computing.Net

Solution Center

Free IT eBook

Howtos

Site Search

Message Find

RSS Feeds

Install Guides

Data Recovery

About

Home
Reply to Message Icon Go to Main Page Icon

JavaScript change style on events

Original Message
Name: Laler
Date: March 29, 2006 at 05:01:04 Pacific
Subject: JavaScript change style on events
OS: XP Pro
CPU/Ram: 2800/512
Model/Manufacturer: amd
Comment:
Hello,

How to make this kind of logic works? :D

<a onmouseover="document.getElementById['foo'].style.visibility='visible'" href="foo">Foo</a>

<div id="foo" style="visibility: hidden;">Bar</div>

Basically I want to show and hide a div on mouseovers/outs and I want to do it as simple as possible but also as cross-browser as possible.

Thanks for any comment


---
Site of the Day


Report Offensive Message For Removal


Response Number 1
Name: Michael J (by mjdamato)
Date: March 29, 2006 at 07:24:54 Pacific
Subject: JavaScript change style on events
Reply: (edit)
Your code is fine except you used brackets "[]" when you should have used parens "()".

<a onmouseover="document.getElementById('foo').style.visibility='visible'"
onmouseout="document.getElementById('foo').style.visibility='hidden'"
href="foo">Foo

<div id="foo" style="visibility: hidden;">Bar</div>

For cross-browser compatibility you might want to look at trying visibility and or display. You might have to use one or both to get the results you want. If a browser does not support either one, then there's nothing you can do in CSS to make it happen, you would probably have to get into some more advanced JavaScript.

Also, you need to change the href to actually point to a valid url if you want it to be a link or you could set the href to "#" or just make it a div (makes the most sense if it will not be a link).
Michael J


Report Offensive Follow Up For Removal

Response Number 2
Name: Laler
Date: March 29, 2006 at 08:52:49 Pacific
Subject: JavaScript change style on events
Reply: (edit)
lol, ok :D

I looked back at those so many pages I searched before, and none of them use brackets, didn't know how it get into the code :D

Thanks for the other suggestion, I'll use both display and visibility, and yes the href will point to a real link.

Thanks again Michael.

---
Site of the Day


Report Offensive Follow Up For Removal

Response Number 3
Name: Dr. Nick
Date: April 1, 2006 at 23:11:56 Pacific
Subject: JavaScript change style on events
Reply: (edit)
Just for kicks and giggles...

The only downside to using "#" as a 'null' in the href attribute is that it will cause the browser to jump to the top of the page. This can be a pain sometimes.

An alternative is to set the href to "javascript:;". The browser will do nothing at all with this.


Report Offensive Follow Up For Removal




Use following form to reply to current message:

   Name: From My Computing.Net Settings
 E-Mail: From My Computing.Net Settings

Subject: JavaScript change style on events

Comments:

 
  Homepage URL (*): 
Homepage Title (*): 
         Image URL: 
 


Data Recovery Software




My PC has been hijacked!

Lexmark 2600 Printer Issues

btk1w1 infected start here post

Unwanted message remians on screen

Slow boot time


The information on Computing.Net is the opinions of its users. Such opinions may not be accurate and they are to be used at your own risk. Computing.Net cannot verify the validity of the statements made on this site. Computing.Net and Computing.Net, LLC hereby disclaim all responsibility and liability for the content of Computing.Net and its accuracy.
PLEASE READ THE FULL DISCLAIMER AND LEGAL TERMS BY CLICKING HERE

All content ©1996-2007 Computing.Net, LLC