Connecting Tech Pros Worldwide Forums | Help | Site Map

Refer to an image in JavaScript

Samuel Shulman
Guest
 
Posts: n/a
#1: Mar 1 '07
I have an image with id 'SolitaireImage'

How can I refer to it in JavaScript? I want to change the src attribute

Thank you,
Samuel



Randy Webb
Guest
 
Posts: n/a
#2: Mar 1 '07

re: Refer to an image in JavaScript


Samuel Shulman said the following on 3/1/2007 5:12 PM:
Quote:
I have an image with id 'SolitaireImage'
>
How can I refer to it in JavaScript? I want to change the src attribute
Same way you do any other object with an ID.
theImage = document.getElementById('SolitaireImage')
--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/index.html
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
nice.guy.nige
Guest
 
Posts: n/a
#3: Mar 2 '07

re: Refer to an image in JavaScript


While the city slept, Samuel Shulman (samuel.shulman@ntlworld.com)
feverishly typed...
Quote:
I have an image with id 'SolitaireImage'
>
How can I refer to it in JavaScript? I want to change the src
attribute
Not sure about ID, but if you use the NAME attribute...

<img name="blah"...>

<script type="text/javascript">
<!-- Hide

function changeImage(var source)
{
document.images.blah.src = source;
}

// dunhidin -->
</script>

Or something like that...

Cheers,
Nige

--
Nigel Moss http://www.nigenet.org.uk
Mail address will bounce. nigel@DOG.nigenet.org.uk | Take the DOG. out!
"Your mother ate my dog!", "Not all of him!"


Samuel Shulman
Guest
 
Posts: n/a
#4: Mar 2 '07

re: Refer to an image in JavaScript


Thanks Randy and Nige

It works nicely

"Randy Webb" <HikksNotAtHome@aol.comwrote in message
news:kMqdnVMmV73_z3rY4p2dnA@telcove.net...
Quote:
Samuel Shulman said the following on 3/1/2007 5:12 PM:
Quote:
>I have an image with id 'SolitaireImage'
>>
>How can I refer to it in JavaScript? I want to change the src attribute
>
Same way you do any other object with an ID.
theImage = document.getElementById('SolitaireImage')
--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/index.html
Javascript Best Practices -
http://www.JavascriptToolbox.com/bestpractices/

Richard Cornford
Guest
 
Posts: n/a
#5: Mar 2 '07

re: Refer to an image in JavaScript


On Mar 2, 12:35 am, nice.guy.nige wrote:
<snip>
Quote:
Not sure about ID, but if you use the NAME attribute...
<snip>
Quote:
document.images.blah.src = source;
The W3C Level 2 HTML DOM specification says that IDed IMG elements
should be referencable as named properties of the - document.images -
collection.

Richard.

Closed Thread