javascript help
- Started
- Last post
- 5 Responses
- toastie
hey, does anyone have any idea why i cant access an img tag by name from a javascript function?
like
document.getElementById("imgId... = "blah.gif";
where imgId is the name of the img tag passed to the function.
- welded0
You're using getElementById but you are passing it the name value, not the id, so unless they happen to match it wont work. Also, and I don't know if it'll matter, but you shouldn't need quotes around the variable name.
I'm no javascript wiz, but it seems to me that's your primary malfunction.
- unfittoprint0
this
document.getElementById(' idOfYouImage').src = 'new/source';or
document.getElementById( 'idOfYouImage' ).setAttribute( 'src', 'new/source' );
should work.
- toastie0
ah, you're right, i had it assigned a name, not an id in the tag, changing it worked. and you're right, you dont need the quotes, i put them there trying to figure out what was wrong.
- toastie0
thank you ^^
- welded0
Glad to help.
:)