How would I get a css property inside javascript!
ex :
<style>
#body{
background:red;
}
</style>
<script>
function valid(form){
alert('enter');
var test = document.getElementById('body').style.background ;
alert(test');
}
</script>
</head>
<body id="body">
On alert I am not able to get the background color!
The
styleproperty on elements only reflects the style information in the element itself (such as via thestyleattribute in the markup), not anything applied by style rules. To get those, you’d needgetComputedStyle:Live example
Off-topic: Some of this stuff is made easier by libraries such as jQuery, Prototype, YUI, Closure, or any of several others.