Welcome to WebmasterWorld Guest from 184.108.40.206 , register , free tools , login , search , pro membership , help , library , announcements , recent posts , open posts Become a Pro Member
How do we discriminate between:
<IMG SRC=".." ALT=""> (empty ALT tag)
and <IMG SRC=".."> NULL alt tag.
Is this possible and how?
I have had a play and a search for you, but as I suspected, without any luck... so as far as I know there is no way of knowing the difference using JS.
According to this
article on MSDN [ msdn.microsoft.com], I think you should be able to... I haven't managed to get it to work yet though.
- Return Value [of the getAttribute() method] Variant that returns a String, number, or Boolean value as defined by the attribute. If the attribute is not present, this method returns null.
Maybe if you tell us what you're trying to do with this information we can still help you out?
The problem with getAttribute() is that it appears to know that ALT is a valid attribute name for IMG and so returns "" (this behaviour is helpful in most cases). If you invent a new attribute name eg XATT then it returns "" and null depending on whether it is present.
All I can think of is to check the actual HTML like
if (img.att=="" && indexOf(img.outerHTML, "ALT=")) raingerpete
[ edited by: tedster at 6:55 pm (utc) on April 8, 2003]