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"
});
精彩评论