Search code examples
javascriptjqueryinternet-explorer-6imagemap

How to test for presence of "nohref" attribute in IE6/7?


The nohref attribute on an area tag causes the are to be specifically excluded from an image map. It works in IE 6-7 in that you can see the mouse pointer is not changed when hovering over an area marked as such. The rectangle has a "nohref" and the blue circle doesn't.

http://jsfiddle.net/ZNMEC/7/

However, I can't figure out any way to programatically test for it in Javascript that works in IE 6 & 7. getAttribute always returns false whether the attribute is present or not. jQuery .attr doesn't work either.


Solution

  • By the XHTML standard, nohref attributes should be written as nohref="nohref". If you do that, you can easily test for it as .attr('nohref') will return the string "nohref".

    However this attribute is no longer supported in HTML5. From the W3C working draft:

    The nohref attribute on the area element is obsolete. Omitting the href attribute is sufficient.

    Therefore you can test for it by if($('area').attr('href')){ /* href is set */ }.