473,566 Members | 3,273 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Javascript to enable the :hover pseudo class on IE?

As you might know, IE doesn't support the :hover pseudo-class on every tag
(just the "a" tag AFAIK)
Is there a simple JavaScript that would solve the problem?
I have images that have a light blue outline, and when I pass the mouse
over, the outline turns to red.

#featured img {
display: block;
border: 1px solid #DCDFE8;
padding: 1px;
margin: 10px;
margin-left: auto;
margin-right: auto;
}
#featured img:hover {
border: 1px solid #FF0000;
}
Of course it doesn't work on IE. How would you do?

--

Kerberos.

http://www.opera.com
http://www.freebsd.org
http://www.auriance.com
http://www.osresources.com
http://exodus.jabberstudio.org
Jul 21 '05 #1
8 6987
On Mon, 10 Jan 2005 16:03:32 -0200, Kerberos <me@privacy.net > wrote:

[:hover emulation in IE]
Is there a simple JavaScript that would solve the problem?


It probably would have been better to ask this in comp.lang.javas cript.

[snip]

<img ...
onmouseover="if (this.style){th is.style.border Color='red';}"
onmouseout="if( this.style){thi s.style.borderC olor='';}">

You could of course use #RGB to specify the colour, but the keyword was
shorter.

Mike

--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.
Jul 21 '05 #2
*Kerberos* <me@privacy.net >:

As you might know, IE doesn't support the :hover pseudo-class on every
tag (just the "a" tag AFAIK)
Is there a simple JavaScript that would solve the problem?


Well, there is Dean Edwards's IE7, which features that and more.

--
If the glass is half full or half empty
depends on if you are pouring or drinking.
Jul 21 '05 #3
Em Mon, 10 Jan 2005 23:03:34 GMT, Michael Winter
<M.******@bluey onder.co.invali d> escreveu:
<img ...
onmouseover="if (this.style){th is.style.border Color='red';}"
onmouseout="if( this.style){thi s.style.borderC olor='';}">


Thanks, I'm used this in a previous site, but I was looking for another
solution because it's a little heavy, because there as quite a lot of
photos...

I think I'll just forget it, because it doesn't decrease accessibility.
It'll look just nicer in browsers like Opera this time :)

--

Kerberos.

http://www.opera.com
http://www.freebsd.org
http://www.auriance.com
http://www.osresources.com
http://exodus.jabberstudio.org
Jul 21 '05 #4
/Christoph Paeper/:
*Kerberos* <me@privacy.net >:
As you might know, IE doesn't support the :hover pseudo-class on
every tag (just the "a" tag AFAIK)
Is there a simple JavaScript that would solve the problem?


Well, there is Dean Edwards's IE7, which features that and more.


http://dean.edwards.name/IE7/

"Dynamic Pseudo-Classes"
<http://dean.edwards.na me/IE7/compatibility/super-dynamic.html>

--
Stanimir
Jul 21 '05 #5
Em Tue, 11 Jan 2005 14:40:17 +0200, Stanimir Stamenkov
<s7****@netscap e.net> escreveu:
Well, there is Dean Edwards's IE7, which features that and more.


http://dean.edwards.name/IE7/

"Dynamic Pseudo-Classes"
<http://dean.edwards.na me/IE7/compatibility/super-dynamic.html>

Gosh! This is great! Thank you so much!
If you have other goodies, they're welcome ;)
--

Kerberos.

http://www.opera.com
http://www.freebsd.org
http://www.auriance.com
http://www.osresources.com
http://exodus.jabberstudio.org
Jul 21 '05 #6
Kerberos a écrit :

| As you might know, IE doesn't support the :hover pseudo-class on every
| tag (just the "a" tag AFAIK)
| Is there a simple JavaScript that would solve the problem?

Cleaner than repeating "onmouseove r = " code in every element, more
focussed on your problem than IE7, let me point you to the "Suckerfish
Dropdowns" article at http://www.alistapart.com/articles/dropdowns/.

You simply have to adapt the provided JS function (change "nav" to
"featured", obviously) and slighly modify your CSS as follows:

| [...]
| #featured img:hover {

Change this to

#featured img:hover, #featured img.over {

| border: 1px solid #FF0000;
| }

That's what I do. HTH.

--
Daniel Déchelotte
http://yo.dan.free.fr/
Jul 21 '05 #7
On Tue, 11 Jan 2005 10:00:15 -0200, Kerberos <me@privacy.net > wrote:

[snip]
Thanks, I'm used this in a previous site, but I was looking for another
solution because it's a little heavy, because there as quite a lot of
photos...


function colourBorder() {setBorder(this , '#ff0000');}
function restoreBorder() {setBorder(this , '');}
function setBorder(obj, colour) {
if(obj.style) {obj.style.bord erColor = colour;}
}

var featured = null, images;
if(document.get ElementById
&& (featured = document.getEle mentById('featu red'))
&& featured.getEle mentsByTagName)
{
images = featured.getEle mentsByTagName( 'img');
for(var i = 0, n = images.length; i < n; ++i) {
images[i].onmouseover = colourBorder;
images[i].onmouseout = restoreBorder;
}
}

Using that would certainly be more efficient than including the IE7
emulation code, particularly if you removed all unnecessary whitespace.

[snip]

Mike

--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.
Jul 21 '05 #8
Kerberos wrote:
Em Mon, 10 Jan 2005 23:03:34 GMT, Michael Winter
<M.******@bluey onder.co.invali d> escreveu:
<img ...
onmouseover="if (this.style){th is.style.border Color='red';}"
onmouseout="if( this.style){thi s.style.borderC olor='';}">

Thanks, I'm used this in a previous site, but I was looking for another
solution because it's a little heavy, because there as quite a lot of
photos...

I think I'll just forget it, because it doesn't decrease accessibility.
It'll look just nicer in browsers like Opera this time :)


I very much liked the look of

http://www.xs4all.nl/~peterned/csshover.html

though I've not yet used it myself. It keeps the IE script in one place
away from most of your own code which doesn't require a lot of heavy
mods inlined. If you use it, note the comment re serving .htc files with
correct mimetype for IE running under XP+SP2.

--
Michael
m r o z a t u k g a t e w a y d o t n e t
Jul 21 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
2819
by: Andrew Thompson | last post by:
I would like to create a menu that uses the 'active' pseudo-class to highlight the current page, but I cannot get it to work. The URL http://www.lensescapes.com/tst/nav/1.jsp shows the attempts so far, there are links to 3 pages, but (in IE6 and Mozilla?on XP) do not render the link of the current page as yellow on blue. What am I doing...
2
3257
by: Bob P. | last post by:
Hi, basically what I'd like to do is suppress the action that causes the URL to show up in the browser status bar when I roll over a hyperlink. I know I could use the onmouseover event in each anchor tag, but I'd rather be able to do it globally thru my stylesheet, rather than having to futz with each link. Does anyone know a solution for...
1
1573
by: Jean Pion | last post by:
Dear readers, Can I have a class selector the pseudoclasses like: .menuw { general_stuff_for_this_class; } a.menuw:link { special_for_link;} a.menuw:visited {special_for_visited; } a.menuw:hover { special_for_hover; } a.menuw:active { special_for_active; }
8
280177
by: ZakRhino | last post by:
Is there a way to turn this DHTML code into CSS code? If so what is the correct way it should be put in the code? onmouseover="this.style.backgroundColor='#0061D7';" onmouseout="this.style.backgroundColor='#3D93FF';"
3
4885
by: friday13 | last post by:
Hi, I would like to set the link's "visited" pseudo-class with javascript without clicking on the link. My goal is to update the link's color (previously set in the CSS file) to be "visited" without actually clicking on the link and then clicking "back" in the browser. Does anyone know how? Here are the following things I've already...
1
1344
by: Didd | last post by:
I'm building a real-time layout tool where you can change for ex. font sizes and background colors directly by entering appropriate values into specified fields. I'm using JQuery to target HTML-elements (such as body, h1, div etc.) like this: $('#somediv').css("backgroundColor","#000000"); $('a').css("color","#000000"); So, changing...
1
4161
by: GVDC | last post by:
Example server-side JavaScript Web script, Dictionary class //Dictionary class, hash array unlimited length configurable speed/efficiency // printf("<html><body>"); printf("<b>Creating dictionary</b><br\n>"); var dictobj = new Dictionary(5); //dictionary class
0
7584
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8109
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7645
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...
0
6263
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...
1
5485
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...
0
3643
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...
0
3626
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1202
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
926
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.