Connecting Tech Pros Worldwide Help | Site Map

Refer to an image in JavaScript

 
LinkBack Thread Tools Search this Thread
  #1  
Old March 1st, 2007, 09:25 PM
Samuel Shulman
Guest
 
Posts: n/a
Default Refer to an image in JavaScript

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, 09:35 PM
Randy Webb
Guest
 
Posts: n/a
Default 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 1st, 2007, 11:45 PM
nice.guy.nige
Guest
 
Posts: n/a
Default 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, 08:55 AM
Samuel Shulman
Guest
 
Posts: n/a
Default 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, 10:15 AM
Richard Cornford
Guest
 
Posts: n/a
Default 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.

 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,989 network members.