开发者

IE6 not letting JS set attribute

开发者 https://www.devze.com 2023-02-04 05:11 出处:网络
document.getElementById(\"gD\" + gDay + gMonth + gYear).setAttribute(\"class\", \"gDay gDayHover\"); This works fine in all modern browsers, unfortunately for me it needs to work in older versions.I
document.getElementById("gD" + gDay + gMonth + gYear).setAttribute("class", "gDay gDayHover");

This works fine in all modern browsers, unfortunately for me it needs to work in older versions. I'm using IE8's compatibil开发者_StackOverflowity mode, and it doesn't seem to cope with this piece of code.

It's getting the element fine, but not changing it's class. Any ideas?


You might want to have a look at the className property. This should work fine in IE6 and above.

var elem = document.getElementById("gD" + gDay + gMonth + gYear);
elem.className = "gDay gDayHover";
0

精彩评论

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

关注公众号