Accessing a:hover attribute using DOM methods?

A

Animesh K

Hello All:

I want to access CSS's a:hover background-image property using
Javascript's DOM method. The image has a name zoomin, so I was trying
something like

document.zoomin.a:hover.backgroundImage ="blah";

but it failed, as you would guess.

Can someone suggest how to access the relevant property?

Best regards,
Animesh
 
R

RobG

Hello All:

I want to access CSS's a:hover background-image property using
Javascript's DOM method. The image has a name zoomin, so I was trying
something like

document.zoomin.a:hover.backgroundImage ="blah";

but it failed, as you would guess.

You are trying to access a pseudo class which is a CSS selector, it is
not an attribute of the HTML element. Trying to set it via the
element is doomed. :-(

You want a selector like:

<head>
<title>Zoomin test</title>
<style type="text/css">
#foo a:hover { background-image: url('zoomin.jpg');}
</style>
</head>
<body>
<div id="foo"><a href="#">blah</a></div>
</body>

Now, if you want to use script to modify the CSS rule, try:

<URL: http://www.thescripts.com/forum/post343885-2.html >

or search the archives for something like:

"modify css stylesheet rules selector"
 
A

Animesh K

RobG said:
On Jul 10, 5:05 am, Animesh K <[email protected]> wrote:
You are trying to access a pseudo class which is a CSS selector, it is
not an attribute of the HTML element. Trying to set it via the
element is doomed. :-(

You want a selector like:

<head>
<title>Zoomin test</title>
<style type="text/css">
#foo a:hover { background-image: url('zoomin.jpg');}
</style>
</head>
<body>
<div id="foo"><a href="#">blah</a></div>
</body>

Now, if you want to use script to modify the CSS rule, try:

<URL: http://www.thescripts.com/forum/post343885-2.html >

or search the archives for something like:

"modify css stylesheet rules selector"

Thanks Rob! Seems there is no easy way around this issue. I wish these
things will be added in the future versions.
 
R

RobG

Animesh said:
Thanks Rob! Seems there is no easy way around this issue. I wish these
things will be added in the future versions.

It is already "added" via the methods used in Martin's stylesheet
manipulation code. What you are trying to manipulate is a CSS rule,
not a property of any particular element. It's the same as trying to
change a rule applied to a CSS class rather than changing the class
applied to an element.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top