Why is style property of span undefined in this code.I can't figure out the answer.Thank you in advance.
<html>
<head>
<script>
function func(){
var span1 = document.createElement("span").appendChild(document.createTextNode("Yellow"));;
document.getElementById("p1").appendChild(span1);
span1.style.color = "Yellow";
}
</script>
</head>
<body>
<button onclick = "func();">Click</button>
<p id = "p1">Main paragraph</p>
</body>
</html>
Aucun commentaire:
Enregistrer un commentaire