开发者

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

开发者 https://www.devze.com 2023-03-10 11:38 出处:网络
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 mar

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 "no开发者_如何学运维href" 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.


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 */ }.


To select the area elements with the nohref attribute you can use the attribute-equals notation:

$('area[nohref]');

To demonstrate this being used:

alert($('area[nohref]').length);

JS Fiddle demo.

Reference:

  • attribute-equals selector.
0

精彩评论

暂无评论...
验证码 换一张
取 消