User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the JavaScript / DHTML / AJAX section within the Web Development category of DaniWeb, a massive community of 402,522 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,592 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our JavaScript / DHTML / AJAX advertiser: Lunarpages Web Hosting
Views: 7779 | Replies: 6
Reply
Join Date: Jun 2007
Posts: 2
Reputation: winbach is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
winbach winbach is offline Offline
Newbie Poster

Question Can't change CSS style for "onClick" text link

  #1  
Jun 24th, 2007
Greetings. I am using this code for a photo gallery.

<script language="JavaScript">
function LoadGallery(pictureName,imageFile,titleCaption,captionText)
{
if (document.all)
{
document.getElementById(pictureName).style.filter="blendTrans(duration=1)";
document.getElementById(pictureName).filters.blendTrans.Apply();
}
document.getElementById(pictureName).src = imageFile;
if (document.all)
{
document.getElementById(pictureName).filters.blendTrans.Play();
}
document.getElementById(titleCaption).innerHTML=captionText;
}
</script>

With an onclick statement like this:

<a href="#_self" onclick="LoadGallery('Gallery', 'image.jpg', 'Caption', 'captiontext')">Link</a>

It totally works but I would like to have the "Link" when clicked change from the style designated in the <td> tag below:

<td class="style 1">

To another CSS style .style 2

I am stuck on how to get this to work. I have tried many things with no luck. Do I need another function or could it be added to my gallery script? Thanks for your time and assistance in advance.

Lisa
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Jun 2006
Location: India
Posts: 6,812
Reputation: ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold 
Rep Power: 23
Solved Threads: 339
Moderator
Featured Poster
~s.o.s~'s Avatar
~s.o.s~ ~s.o.s~ is offline Offline
Rebellion Revamped

Re: Can't change CSS style for "onClick" text link

  #2  
Jun 24th, 2007
  1. <script>
  2. function changeStyle(id, newClass)
  3. {
  4. document.getElementById(id).style.className = newClass;
  5. }
  6. </script>
  7. ....
  8. <td id="oneTd" class="style1" onclick="changeStyle(this.id, 'style2');" >
  9. Hello
  10. </td>
  11.  
  12. // Or simply in one line
  13.  
  14. <td id="oneTd" class="style1" onmouseover="this.style.className='style2';">
  15. Hello
  16. </td>
Last edited by ~s.o.s~ : Jun 24th, 2007 at 9:40 pm.
"I don't accept change. I don't deserve to live."

"Working a real job is a win if you're lazy, greedy, or unmotivated. If you're average, you fit right in. And if you're above average, the basic terms of employment and premise of the arrangement is against your interests."
Reply With Quote  
Join Date: Jun 2007
Posts: 2
Reputation: winbach is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
winbach winbach is offline Offline
Newbie Poster

Re: Can't change CSS style for "onClick" text link

  #3  
Jun 24th, 2007
Greetings. Thanks so much for the reply, however, I am still unable to get this to work.
Here is my code for the table cell.

<td width="186" height="257" valign="top" class="portfolionames" id="oneTd">
<p align="right"><a href="#_self" onclick="LoadGallery('WinbachGallery', '/images/TMIB.jpg', 'WinbachCaption', '<BR>FEATURES: Online Quotes, DHTML menus'); changeStyle(oneTd, 'navred')">Tegner-Miller Insurance</a><br>
</p>
</td>

My file is linked to an outsite stylesheet where these style names are listed. Any assistance to solving this is greatly appreciated.
Reply With Quote  
Join Date: Jun 2006
Location: India
Posts: 6,812
Reputation: ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold 
Rep Power: 23
Solved Threads: 339
Moderator
Featured Poster
~s.o.s~'s Avatar
~s.o.s~ ~s.o.s~ is offline Offline
Rebellion Revamped

Re: Can't change CSS style for "onClick" text link

  #4  
Jun 25th, 2007
> changeStyle(oneTd, 'navred')"
The above one should be changeStyle(this.id, 'navred').

If this still doesn't work, post some working code along with sample stylesheet and images so that we can try it out without writing the same code over again.
"I don't accept change. I don't deserve to live."

"Working a real job is a win if you're lazy, greedy, or unmotivated. If you're average, you fit right in. And if you're above average, the basic terms of employment and premise of the arrangement is against your interests."
Reply With Quote  
Join Date: Feb 2008
Posts: 5
Reputation: zabindia is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
zabindia zabindia is offline Offline
Newbie Poster

Solution Re: Can't change CSS style for "onClick" text link

  #5  
Feb 27th, 2008
The below code what you have suggested earlier doesnt work...

<script>function changeStyle(id, newClass){   
 document.getElementById(id).style.className = newClass;}
</script>

sytle.className will not work when used with document.getElementById
it should be document.getElementById(id).className

instead u need to use this code

<script>
		function changeStyle(id, newClass){
		document.getElementById(id).className = newClass;
</script>
	}
  1. <td id="oneTd" class="style1" onclick="changeStyle(this.id, 'style2');" >Hello</td>
Last edited by peter_budo : Feb 27th, 2008 at 2:48 pm. Reason: Extensive use of colour tags is not best idea
Reply With Quote  
Join Date: Nov 2007
Posts: 86
Reputation: sagedavis is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 6
sagedavis sagedavis is offline Offline
Junior Poster in Training

Re: Can't change CSS style for "onClick" text link

  #6  
Feb 27th, 2008
acutally, you can just use class, since class is the attribute, and I believe that newClass requires quote...

There are times where you have a hard time working with "this.id" use oneTd instead of this.id in your onclick event. since you know what the id is.
Sage
Reply With Quote  
Join Date: Jan 2007
Posts: 2,537
Reputation: MidiMagic is on a distinguished road 
Rep Power: 7
Solved Threads: 110
MidiMagic's Avatar
MidiMagic MidiMagic is offline Offline
Posting Maven

Re: Can't change CSS style for "onClick" text link

  #7  
Mar 1st, 2008
It may be disabled in your browser.

There is a setting to override page colors for links and always use the standard colors.

This is why you should never change the link colors.
Daylight-saving time uses more gasoline
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb JavaScript / DHTML / AJAX Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the JavaScript / DHTML / AJAX Forum

All times are GMT -4. The time now is 6:49 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC