Refer to an image in JavaScript

S

Samuel Shulman

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
 
R

Randy Webb

Samuel Shulman said the following on 3/1/2007 5:12 PM:
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')
 
N

nice.guy.nige

While the city slept, Samuel Shulman ([email protected])
feverishly typed...
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
 
R

Richard Cornford

On Mar 2, 12:35 am, nice.guy.nige wrote:
Not sure about ID, but if you use the NAME attribute...
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top