xhtml <img> name

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
r_barlow
Forum Newbie
Posts: 17
Joined: Mon May 29, 2006 3:13 pm

xhtml <img> name

Post 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?
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

id...

Code: Select all

<img id="image_name" src="yadda.png" />
Roja
Tutorials Group
Posts: 2692
Joined: Sun Jan 04, 2004 10:30 pm

Re: xhtml <img> name

Post 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.
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post 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 :oops: (speaking from experience)
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.
r_barlow
Forum Newbie
Posts: 17
Joined: Mon May 29, 2006 3:13 pm

Post 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
		}
	}
Post Reply