Connecting Tech Pros Worldwide Help | Site Map

Refer to an image in JavaScript

  #1  
Old March 1st, 2007, 10:25 PM
Samuel Shulman
Guest
 
Posts: n/a
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


  #2  
Old March 1st, 2007, 10:35 PM
Randy Webb
Guest
 
Posts: n/a

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/
  #3  
Old March 2nd, 2007, 12:45 AM
nice.guy.nige
Guest
 
Posts: n/a

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!"


  #4  
Old March 2nd, 2007, 09:55 AM
Samuel Shulman
Guest
 
Posts: n/a

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/

  #5  
Old March 2nd, 2007, 11:15 AM
Richard Cornford
Guest
 
Posts: n/a

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
How do I make an Image visible? Cov answers 16 November 7th, 2007 05:55 PM
change an image based on selected option Xerxes answers 3 February 1st, 2006 03:45 PM
Determine if an image has focus after leaving another image. Thomasa Gregg answers 1 November 18th, 2005 02:09 PM
Opening image in new window without padding D. Alvarado answers 14 July 23rd, 2005 10:57 PM