DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Benoit has posted 48 posts at DZone. View Full User Profile

IE Doesn't Support Element.setAttritube('style')

08.02.2007
| 3748 views |
  • submit to reddit
        
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" version="-//W3C//DTD XHTML 1.1//EN" xml:lang="fr">
<head>

<title>.setAttribute('style','');</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<script type="text/javascript">
<!--

window.onload = function() {
	if (navigator.appName == 'Microsoft Internet Explorer') {
		document.getElementById('test').style.cssText = 'background:gray; color:white;';
	} else {
		/* document.getElementById('test').style.cssText = 'background:gray; color:white;'; */
		document.getElementById('test').setAttribute('style', 'background:gray; color:white;');
	}
}

-->
</script>

</head>

<body>

<div id="test">document.getElementById('test').setAttribute('style', 'background:gray; color:white;')</div>

</body>

</html>