MENU

Fun & Interesting

How to ADD/CHANGE HTML using JavaScript 🛠️

Bro Code 22,790 1 year ago
Video Not Working? Fix It Now

#JavaScript #html #tutorial 00:00:00 setup 00:01:10 h1 element 00:09:32 list items // STEP 1 CREATE THE ELEMENT const newH1 = document.createElement("h1"); // STEP 2 ADD ATTRIBUTES/PROPERTIES newH1.textContent = "I like pizza!"; newH1.id = "myH1"; newH1.style.color = "tomato"; newH1.style.textAlign = "center"; // STEP 3 APPEND ELEMENT TO DOM document.body.append(newH1); // document.body.prepend(newH1); // document.getElementById("box1").append(newH1); // document.getElementById("box1").prepend(newH1); // const box4 = document.getElementById("box4"); // document.body.insertBefore(newH1, box4); // const boxes = document.querySelectorAll(".box"); // document.body.insertBefore(newH1, boxes[0]); // REMOVE HTML ELEMENT // document.body.removeChild(newH1); // document.getElementById("box1").removeChild(newH1);

Comment