•
•
•
•
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
![]() |
| |
•
•
Join Date: Jun 2007
Posts: 2
Reputation:
Rep Power: 0
Solved Threads: 0
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
<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
javascript Syntax (Toggle Plain Text)
<script> function changeStyle(id, newClass) { document.getElementById(id).style.className = newClass; } </script> .... <td id="oneTd" class="style1" onclick="changeStyle(this.id, 'style2');" > Hello </td> // Or simply in one line <td id="oneTd" class="style1" onmouseover="this.style.className='style2';"> Hello </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."
"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."
•
•
Join Date: Jun 2007
Posts: 2
Reputation:
Rep Power: 0
Solved Threads: 0
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.
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.
> 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.
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."
"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."
•
•
Join Date: Feb 2008
Posts: 5
Reputation:
Rep Power: 0
Solved Threads: 0
The below code what you have suggested earlier doesnt work...
sytle.className will not work when used with document.getElementById
it should be
instead u need to use this code
<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>
} html Syntax (Toggle Plain Text)
<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
![]() |
•
•
•
•
•
•
•
•
DaniWeb JavaScript / DHTML / AJAX Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
- CSS Style : Links (HTML and CSS)
- Post 5 Articles Get a Rotation Banner Or Text Link (Relevant Link Exchanges)
- Extremely Cheap Sitewide Text Link on Website Design Related Site (Ad Space for Sale)
- Sweet text link network (Relevant Link Exchanges)
Other Threads in the JavaScript / DHTML / AJAX Forum
- Previous Thread: unexpected object
- Next Thread: scrolling images



Hybrid Mode