| | |
Can't change CSS style for "onClick" text link
Please support our JavaScript / DHTML / AJAX advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Jun 2007
Posts: 2
Reputation:
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 10:40 pm.
I don't accept change; I don't deserve to live.
•
•
Join Date: Jun 2007
Posts: 2
Reputation:
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.
•
•
Join Date: Feb 2008
Posts: 5
Reputation:
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 3:48 pm. Reason: Extensive use of colour tags is not best idea
![]() |
Similar Threads
- Extremely Cheap Sitewide Text Link on Website Design Related Site (Ad Space for Sale)
- CSS Style : Links (HTML and CSS)
- Post 5 Articles Get a Rotation Banner Or Text Link (Relevant Link Exchanges)
- Sweet text link network (Relevant Link Exchanges)
Other Threads in the JavaScript / DHTML / AJAX Forum
- Previous Thread: unexpected object
- Next Thread: scrolling images
| Thread Tools | Search this Thread |
ajax ajaxcode ajaxhelp ajaxjspservlets animate automatically beta box browser bug calendar captchaformproblem checkbox child class close column cookies createrange() css cursor dependent disablefirebug dom download dropdown editor element engine error events explorer ext file form forms google gwt gxt hiddenvalue highlightedword html htmlform ie8 iframe image() images internet java javascript jawascriptruntimeerror jquery jsf jsfile jump libcurl math media microsoft mimic object onerror onmouseoutdivproblem onreadystatechange parent pdf php player post problem progressbar rated rating regex runtime scroll search security select session shopping size software sql star stars synchronous text textarea unicode validation w3c web website window windowofwords windowsxp wysiwyg xml \n






