Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

JavaScript Forum


You are currently viewing our JavaScript Forum as a guest. Please register to participate.
Login



Reply
Swapping CLASS using DHTML
Old 12-14-2010, 09:43 AM Swapping CLASS using DHTML
dartiss's Avatar
Experienced Talker

Latest Blog Post:
November
Posts: 32
Name: David Artiss
Location: Nottingham, UK
Trades: 0
I'm attempting to use some inline JavaScript to dynamically alter the CLASS of an image so that is changes when the image is hovered over.

Here's my stylesheet elements (simplified for testing purposes)...

Code:
.ssb img {
    background-color: #f00;
}
.ssb_hov img {
    background-color: #0f0;
}
And here's the code (I've replaced the rather long urls with "[URL]" to make it more readable...

HTML Code:
<a  href="[url]" class="ssb" rel="nofollow"  onmouseover="document.getElementById('delicious_4546').className='ssb_hov';"   onmouseout="document.getElementById('delicious_4546').className='ssb';">
<img src="[url]" id="delicious_4546" alt="Delicious" title="Delicious" class="ssb" style="padding-left: 5px; padding-right: 5px" />
</a>
As far as I can tell, this should work. But it won't. I'm using Firefox.

Anybody have any idea what the problem is?

David.
dartiss is offline
Reply With Quote
View Public Profile Visit dartiss's homepage!
 
 
Register now for full access!
Old 12-14-2010, 09:55 AM Re: Swapping CLASS using DHTML
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,383
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
Just use this.className='name'

or this.style.backgroundColor='colourCode'
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 12-14-2010, 09:57 AM Re: Swapping CLASS using DHTML
dartiss's Avatar
Experienced Talker

Latest Blog Post:
November
Posts: 32
Name: David Artiss
Location: Nottingham, UK
Trades: 0
Quote:
Originally Posted by chrishirst View Post
Just use this.className='name'

or this.style.backgroundColor='colourCode'
That would require me to put the JavaScript on the image and not the anchor, wouldn't it? I guess that also does away with the need for an ID?

David.
dartiss is offline
Reply With Quote
View Public Profile Visit dartiss's homepage!
 
Old 12-14-2010, 10:52 AM Re: Swapping CLASS using DHTML
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,383
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
Use
Code:
this.firstchild.className
then
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 12-14-2010, 11:06 AM Re: Swapping CLASS using DHTML
dartiss's Avatar
Experienced Talker

Latest Blog Post:
November
Posts: 32
Name: David Artiss
Location: Nottingham, UK
Trades: 0
Quote:
Originally Posted by chrishirst View Post
Use
Code:
this.firstchild.className
then
No, I'm quite happy to put the javascript on the images. I was just checking that's what you meant (I only occasionally touch JavaScript so am very rusty!).

So, if I put your original suggestion against the images, sans the ID tag, that should work?

David.
dartiss is offline
Reply With Quote
View Public Profile Visit dartiss's homepage!
 
Old 12-14-2010, 11:11 AM Re: Swapping CLASS using DHTML
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,383
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
Yep. ...


And of course you could use the :hover pseudoclass on the container
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?

Last edited by chrishirst; 12-14-2010 at 11:12 AM..
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Reply     « Reply to Swapping CLASS using DHTML
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.57863 seconds with 12 queries