This is my HTML:
<!DOCTYPE html>
<html>
<head>
<script>
function run(){
var div = document.createElement('div')
div.style.position = 'absolute'
div.style.left = 0
div.style.top = 0
div.onmouseover=function(){
alert('mo')
this.style.opacity = 0
}
div.style.width = 30
div.style.height = 30
div.style.backgroundColor = '#000'
document.body.appendChild(div)
}
onload = run
</script>
<title></title>
</head>
<body>
</body>
</html>
This hmtl runs ok in quirks mode.
But, I know that I need to use some other tags for the html.
I´d like to know…
1 – What other tags should I add, so it runs ok in code validator?
2 – Why my javascript it´s not working with the html5 doctype? (It works ok in quirks mode)
Thanks 🙂
You must specify a units designator for height and width. Eg:
cm,mm,in,pt,pc,px,em,en,ex,ch,rem,vh,vw,vmin, orvmax.Without a units designator, your values have no effect and the div takes up no space on the page.
Also, while the rest of your JavaScript is technically valid, it would be nice to see semi-colons at the end of each statement. But, perhaps that’s just my personal preference.