Click to See Complete Forum and Search --> : css in Javascript
Rik Comery
10-24-2003, 07:05 AM
Hi. I have successfully managed to change the class of a link in Javascript by using the following code
<style>
.link {color: red}
.link:hover {color:blue}
</style>
<a href="#" onClick="changeLink(this)">link</a>
<script>
function changeLink(obj)
{
obj.className="link"
}
</script>
However, what i reaaly want is not to change the class to just "link" but to the change it to "link" in the hover state. I.E it could be written as obj.className="link:hover" (although this obviously does not work)
Is there a way of referencing a "hover" style?
gil davis
10-24-2003, 07:34 AM
The "hover" part is a pseudo-class, not a style. I don't recall seeing it as accessible in JS.
If you change the class of an object to "link", it should inherit the "link:hover" automatically. Is that not what happens?
Rik Comery
10-24-2003, 08:54 AM
Yes it does, but i want the "link:hover" style to be applied WITHOUT hovering over the link. Sounds a bit of a silly request on it's own, i know, but it is just a part of a much larger page.
Khalid Ali
10-24-2003, 10:07 AM
If you want an event to be triggerd byitself then search google for
Synthetic Events
gil davis
10-24-2003, 12:39 PM
Originally posted by emptypath
hello all,
I am a newbie
Please delete this post and start your own thread.
gil davis
10-24-2003, 12:42 PM
Originally posted by Rik Comery
Yes it does, but i want the "link:hover" style to be applied WITHOUT hovering over the link. Sounds a bit of a silly request on it's own, i know, but it is just a part of a much larger page.
Then I suggest you create a class that sets the property you want and skip the hover thing. What are you trying to save by trying to reuse the class?
nkaisare
10-24-2003, 01:47 PM
I dont know what you want to do. But it seems to me that you want your link to be blue colored, but when someone hovers over it or clicks it, the link should turn red. If thats what you want:
a {color: blue}
a:hover, a:active {color: red}
Alternatively, you can do what Gil Davis suggested. Though it seems to me that you may be seeking a complicated solution to a relatively simple problem.
Rik Comery
10-27-2003, 05:41 AM
Sounds like the general opinion is i am trying to use a mallet to crack a nut. :)
I will try to review exactly what i want a look for a simpler solution.
Thanks for all your help