I've had this confusion since long. There is an error called cannot read property of null on chrome inspector.
Upon searching and reading, i found that a property (eg style) can be applied to a DOM element, but if it is rendered as a javascript object it gives the above error.
So how do i go about this?
<html>
<head>
<style>
#test {background:black;width:30px;height:30px;}
</style>
<script>
var a = document.getElementById('test');
a.style.background = "#f00";
</script>
</head>
<body>
<div id="test">
</div>
</body>
</html>
When i did alert(typeof a); it gives as object. So how do I, in general, change properties of elements ??
adoes contain a DOM element, and the way you are referencing the properties is correct and should work if the element is in the DOM when the script runs.