This is a discussion on "Help using document.getElementById" within the JavaScript Forum section. This forum, and the thread "Help using document.getElementById are both part of the Program Your Website category.
|
|
|
|
|
![]() |
||
Help using document.getElementById
|
||
| Notices |
![]() |
|
|
LinkBack | Thread Tools |
|
#1
|
|||
|
|||
|
Help using document.getElementById
Hi!
I have this piece of javascript which enables some nifty image and text swapping, however I would like it to also include a link around the main image tag but can't get it to work, can anyone tell me what I have to add? I have tried adding a link id and another line to my javascript code but it does not add the link. Here's the script:
|
|
|
|
#2
|
|||
|
|||
|
Re: Help using document.getElementById
<script type="text/javascript">
function replaceMainImage(NEWTEXT, NEWIMAGE, link) { document.getElementById("thecontainer").innerHTML = '<a href="'+ link +'"><img name="mainimage" src="'+NEWIMAGE+'" alt="Main image"></a?'; document.getElementById("description").innerHTML = ''+NEWTEXT+''; } </script> <a href="javascript:void(0);" title="Cow With Horns" onclick="replaceMainImage('Cow With Horny Horns', 'images/photo_main_cowhorns.png', 'url_you_for_anchor');"> <img border="0" width="97px" height="76px" alt="Photo - Cow With Horns" src="images/photo_cowhorns.png"> </a> |
|
#3
|
|||
|
|||
|
Re: Help using document.getElementById
How the hell do you edit posts in this forum?
I think that is what you wanted. Just replace 'url_you_for_anchor' (which is how it came out when i tried to type 'url_for_your_anchor'). Each call to the function without a url as an argument will give an invalid number of arguments error, so update all your previous calls to it. |
|
#4
|
|||
|
|||
|
Re: Help using document.getElementById
I have a little button at the bottom of my posts called Edit, it is really faint though.
Yes! Thank you very very much! I feel so thick, it looks so obvious, duh! I really ought to be able to work this kind of thing out for myself.. oh well, that's what forums are for. |
![]() |
| Thread Tools | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| document.getElementById and document.getElementByName is not working in FF | dhineraj | JavaScript Forum | 3 | Jul 26th, 2007 20:23 |
| document.getElementById("userProfileCheck") is not working in Mozilla Firefox | dhineraj | JavaScript Forum | 1 | Jul 20th, 2007 05:32 |
| document.getElementById is not working in Mozilla Firefox | dhineraj | JavaScript Forum | 3 | Jul 20th, 2007 02:31 |
| document.getElementById[objectID].style now working on Mozilla Browser | yogeshid | JavaScript Forum | 1 | May 25th, 2007 09:30 |
| new problem. document.getElementById().width returning unassigned. why? | sanchopansa | JavaScript Forum | 2 | Jul 22nd, 2006 20:23 |