topic description
this is an exercise in the art of js dom programming. I want some animation, but I can"t set the style property of the element with js;
related codes
/ / Please paste the code text below (do not replace the code with pictures)
< html >
<head>
<meta charset="utf-8">
<title></title>
<script type="text/javascript">
function addLoadElement(func){
var oldonload = window.onload;
if(typeof window.onload != "function"){
window.onload = func;
}else{
window.onload = function(){
oldonload();
func();
}
}
}
function positionMessage(){
if(!document.getElementsByTagName) return false;
if(!document.getElementsByTagName("p")) return false;
var elem = document.getElementsByTagName("p");
elem.style.position = "absolute";
elem.style.top = "500px";
elem.style.left = "100px";
}
addLoadElement(positionMessage);
</script>
</head>
<body>
666666
</body>
< / html >
what result do you expect? What is the error message actually seen?
problem description
error occurred [Web browser] "Uncaught TypeError: Cannot set property "position" of undefined" / HelloHBuilder/new_file.html (22)
I want to know what went wrong.