开发者

Why can't I set attribute "TYPE" of LI element in IE?

开发者 https://www.devze.com 2022-12-30 07:37 出处:网络
I\'ve just come to an unusual beghavior of Internet Explorer IE (v8.0.6001.18904). When I try to set \"type\" attribute of any <LI> element, it will result into error.

I've just come to an unusual beghavior of Internet Explorer IE (v8.0.6001.18904). When I try to set "type" attribute of any <LI> element, it will result into error. I used jQuery (v1.32):

$('<li>').attr("type", "test");

or

$('<li type="test">');

The same thing works for DIV. LI element does not seem to have "type" attribute reserved by HTML or XHTML definitions. It also might be jQuery issue.

So开发者_如何学Clution is simple - just use another attribute name :-)

But is there someone out there who knows WHY does this error occur? Could it happen with another attribute names? Why the error comes with LI element only?

UPDATE: Quick solution for this issue:

$('<li>').data("type", "test");


Instead of using attributes for this, jQuery provides another mechanism with .data(), a quick example:

$("li").data("type", "test");

$("li").click(function() {
  alert($(this).data("type")); //alerts "test"
});
0

精彩评论

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