Im developing a web page and im using some javascripts on the pages to move some html elements, but i found that javascript code is not working when <!doctype html>
or any type of <!doctype> s added to the top of the page ! what is this error?
I search on google and i found <!doctype html> is the correct format even stackoverflow source code has it but when i used it javascripts not working but when it removed script working fine & html object is moving but my styles are gone away because of removing <!doctype html>
<!doctype html> when this line removed it works(html element is moving)
<html>
<head>
<script type="text/javascript">
function scrollDiv(){
var obj = document.getElementById("movingDiv");
obj.style.left = 100;
obj.style.top = 10;
}
document.onclick = scrollDiv;
</script>
</head>
<body class="body">
<div class="maindiv" id="mainDiv">
<div class="html_js_code" style="text-align:center;">
<div id="movingDiv" style="position:absolute;left:100pt;top:10pt;border:1px blue
outset;width:160px;background-color:lightyellow;font-weight:bold;">Moving Div</div>
</div>
</div>
</body>
</html>
Without a doctype, the browser assumes that unlabelled lengths are in pixels. With a doctype, they require an explicit unit.