Page 1 of 1
xhtml <img> name
Posted: Thu Jun 01, 2006 2:19 pm
by r_barlow
Hey,
I have an image which I've set its name property because its involved in some javascript rollover.
When I try to validate the page in XHTML strict it says the name has been deprecated.
If I can't give the <img> a name, how am I supposed to access it with javascript?
Posted: Thu Jun 01, 2006 2:24 pm
by RobertGonzalez
id...
Code: Select all
<img id="image_name" src="yadda.png" />
Re: xhtml <img> name
Posted: Thu Jun 01, 2006 2:52 pm
by Roja
r_barlow wrote:I have an image which I've set its name property because its involved in some javascript rollover.
When I try to validate the page in XHTML strict it says the name has been deprecated.
If I can't give the <img> a name, how am I supposed to access it with javascript?
As mentioned, the "id" attribute is ideal for individual/unique elements (keep in mind that you cannot use the same ID twice). If you need to address multiple similar items, you can use the "class" attribute instead.
Posted: Thu Jun 01, 2006 3:11 pm
by s.dot
using element ids instead of names also gives you more cross-browser compatibility, depending on what you're doing.
getElementById("elementName") doesn't tend to work too well in standards compliant browsers

(speaking from experience)
Posted: Thu Jun 01, 2006 4:03 pm
by r_barlow
Thanks a lot!!
If getElementById isn't very good... how should I access the images?
right now I have:
Code: Select all
function imgOn(imgName, prodName)
{
if (document.images)
{
document.getElementById(imgName).src = prodName.src
}
}
function imgOff(imgName)
{
if (document.images)
{
document.getElementById(imgName).src = testoff.src
}
}