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?
xhtml <img> name
Moderator: General Moderators
- RobertGonzalez
- Site Administrator
- Posts: 14293
- Joined: Tue Sep 09, 2003 6:04 pm
- Location: Fremont, CA, USA
id...
Code: Select all
<img id="image_name" src="yadda.png" />Re: xhtml <img> name
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.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?
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)
getElementById("elementName") doesn't tend to work too well in standards compliant browsers
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
Thanks a lot!!
If getElementById isn't very good... how should I access the images?
right now I have:
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
}
}