I am trying to change the style of element by using JavaScript, however, I get this error when I try to: test.html:4 Uncaught TypeError: Cannot read property 'style' of null at test.html:4
This is my code:
<html>
<head>
<script type="text/javascript">
document.getElementById("test").style.marginTop="20px";
</script>
</head>
<body>
<p id="test">
this is a test
</p>
</body>
</html>
I am new to JavaScript, so sorry if I am doing something completely wrong, but everything seems fine to me. I'm probably doing some dumb mistake.