homepage Welcome to WebmasterWorld Guest from 107.20.34.144
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
Forum Library, Charter, Moderator: open

JavaScript and AJAX Forum

    
Javascript - differentiating between NULL and empty alt attributes
How can I find/change a script to discriminate between NULL and empty.
raingerpete

10+ Year Member



 
Msg#: 350 posted 12:58 pm on Apr 8, 2003 (gmt 0)

hi,

How do we discriminate between:

<IMG SRC=".." ALT=""> (empty ALT tag)
and <IMG SRC=".."> NULL alt tag.

Is this possible and how?

Pete

 

joshie76

WebmasterWorld Senior Member 10+ Year Member



 
Msg#: 350 posted 3:47 pm on Apr 8, 2003 (gmt 0)

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?

Iguana

WebmasterWorld Senior Member 10+ Year Member



 
Msg#: 350 posted 4:22 pm on Apr 8, 2003 (gmt 0)

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

10+ Year Member



 
Msg#: 350 posted 4:50 pm on Apr 8, 2003 (gmt 0)

What I would like to achive is to adjust the following javascript favelet to not just show ALT tags when they are provided by also highlight when ALTs are not declared (but not when asigned ="".

javascript:(function(){function toArray (c){var a, k;a=new Array;for (k=0; k<c.length; ++k)a[k]=c[k];return a;}var images, img, altText;images=toArray(document.images);for (var i=0; i<images.length; ++i){img=images[i];altText=document.createTextNode(img.alt);img.parentNode.replaceChild(altText, img)}})();

ideas?

[edited by: tedster at 6:55 pm (utc) on April 8, 2003]

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved