Add class in body tag if IE7 browser – Javascript / jQuery / Conditional comment

[javascript]
<!– Javascript –>
var IE7 = window.navigator.userAgent.match(/msie 7.0/gi);
if(IE7 != null){
window.onload = function(){document.body.className="IE7";};
}

<!– jQuery –>
$(document).ready(function(){
var browser = $.browser.msie;
var version = $.browser.version;

if(browser != null && version == "7.0"){
$("body").addClass("IE7");
}
});

<!– Conditional comment –>
<!–[if IE 7]>
<script type=’text/javascript’>window.onload = function(){document.body.className="IE7";};</script>
<![endif]–>
[/javascript]

Leave a Reply