开发者

Use JavaScript to add a Class to the <html> element respective to the browser

I kind of know how Modernizr works, by adding a Class to the <html>开发者_Python百科 element, I know that jQuery Browser Detection is deprecated, is there a way to detect and add a class ?


Detecting a browser is not difficult (though generally not recommended and occasionally inaccurate). If you're familiar with modernizr, then you should know that feature detection is much more maintainable and accurate mechanism for identifying which behavior you should use in the host browser. For actual browser detection (again, not recommended), I'd suggest reading this Mozilla article: https://developer.mozilla.org/En/Browser_Detection_and_Cross_Browser_Support.

For setting a class, that's much easier. To set a class on the body object, you would just do this:

document.body.className = "xxxx";

or to add a class, you would use this:

document.body.className += " xxxxx";
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜