PDA

View Full Version : XML & "name" attribute


NoShftShck
10-16-2009, 08:52 PM
Little bit of a newbie at web development in general, let alone validating to XHTML.

<a href="./LOGIN/login.html" onmouseover="document.login.src='./images/nav_login_active.png';" onmouseout="document.login.src='./images/nav_login_inactive.png';"><img id="login" name="login" class="login" src="./images/nav_login_inactive.png" border="0px"/></a>

I got something like what's above going on for temporary usage in navigation. I know "name" for <img> has been taken of out XHTML and I have heard you can't use "name" without "id" but it still isn't validating.

Any thoughts??

Thanks

Arbitrator
11-02-2009, 06:19 AM
Any thoughts??Access elements via their IDs and the getElementById method instead:

<a href="./LOGIN/login.html" onmouseover="document.getElementById('login').setAttribute('src', './images/nav_login_active.png');" onmouseout="document.getElementById('login').setAttribute('src', './images/nav_login_inactive.png');"><img id="login" class="login" alt="login" src="./images/nav_login_inactive.png" style="border-width: 0;"/></a>

Note also that the border attribute is deprecated (use CSS) you forgot the text alternative for the image (i.e., alt attribute). I changed the border attribute to the style attribute to correct the former and added filler text for the latter (that you should change to something appropriate for your purposes).

Arbitrator
11-02-2009, 06:23 AM
Actually, if you're using XML-based XHTML, then proper practice is to use the namespace-aware method setAttributeNS (instead of setAttribute):

<a href="./LOGIN/login.html" onmouseover="document.getElementById('login').setAttributeNS(null, 'src', './images/nav_login_active.png');" onmouseout="document.getElementById('login').setAttributeNS(null, 'src', './images/nav_login_inactive.png');"><img id="login" class="login" alt="login" src="./images/nav_login_inactive.png" style="border-width: 0;"/></a>