Computing.Net > Forums > Web Development > JavaScript change style on events

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

JavaScript change style on events

Reply to Message Icon

Name: Laler
Date: March 29, 2006 at 05:01:04 Pacific
OS: XP Pro
CPU/Ram: 2800/512
Product: 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



Sponsored Link
Ads by Google

Response Number 1
Name: Michael J (by mjdamato)
Date: March 29, 2006 at 07:24:54 Pacific
Reply:

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


0

Response Number 2
Name: Laler
Date: March 29, 2006 at 08:52:49 Pacific
Reply:

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


0

Response Number 3
Name: Dr. Nick
Date: April 1, 2006 at 23:11:56 Pacific
Reply:

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.


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Web Development Forum Home


Sponsored links

Ads by Google


Results for: JavaScript change style on events

Netscape javascript problems www.computing.net/answers/webdevel/netscape-javascript-problems/986.html

JavaScript - Table+iFrame on Yoga?! www.computing.net/answers/webdevel/javascript-tableiframe-on-yoga/3226.html

sequentially open windows in frame www.computing.net/answers/webdevel/sequentially-open-windows-in-frame/230.html