akiloama
11-25-2020, 06:21 AM
I’m learning Javascript these days,using The book called Dom programming art
Here is the problem,I want to use JS to create content,but nothing happen when I open my html document. What’s the problem? Thank you
Here is the code below:
window.onload=function(){
var para=document.creatElement("p");
var txt=document.creatTextNode("hello world");
para.appendChild(txt);
var testdiv=document.getElementById("testdiv");
testdiv.appendChild(para);
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8"/>
<title>Test</title>
</head>
<body>
<div id="testdiv">
</div>
<script type="text/javascript" src="scripts/example.js"></script>
</body>
</html>
}
Here is the problem,I want to use JS to create content,but nothing happen when I open my html document. What’s the problem? Thank you
Here is the code below:
window.onload=function(){
var para=document.creatElement("p");
var txt=document.creatTextNode("hello world");
para.appendChild(txt);
var testdiv=document.getElementById("testdiv");
testdiv.appendChild(para);
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8"/>
<title>Test</title>
</head>
<body>
<div id="testdiv">
</div>
<script type="text/javascript" src="scripts/example.js"></script>
</body>
</html>
}