I'm trying to add a button to my webpage using JavaScript but the console is giving me an error saying:
scripts.js:35 Uncaught DOMException: Failed to execute 'appendChild' on 'Node': Only one element on document allowed.
// 7: Create a <button> element, and set its text to 'Delete'
// Add the <button> inside the '.extra' <div>
const button = document.createElement('button');
button.innerHTML = "Delete";
const buttonPlace = document.getElementsByClassName('.extra')[0];
document.appendChild(button);
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="css/main.css">
<title>Practice Manipulating the DOM</title>
</head>
<body>
<div class="container">
<h1></h1>
<p class="desc"></p>
<ul>
<li><input> Play music</li>
<li><input> Swim</li>
<li><input> Bike ride</li>
<li><input> Code</li>
</ul>
<div class="extra">
<p>This is extra content you need to delete.</p>
</div>
</div>
<script src="js/scripts.js"></script>
</body>
</html>
Any idea on what's going on? Thanks for your help!
button.innerHTML->button.textContent? Also, you're inserting intohtmlnotbody... try usingdocument.body.appendChildinstead.getElementsByClassName().