0
How to make js affect html
I know that if you use document.body.innerHTML = anything; that it will display on the web screen but it also removes everything in the html <body>, is there a way to make is change just a line of text instead of the whole body? I already tried changing the .body part to something like .p or .h1 but it didn’t work. Im sure there’s a fix, I’m just very new to coding.
3 Respostas
+ 5
You're on the right path.
Check out this code I made with the help of another mentor Lisa.
You'll see this section:
let resbtn = document.getElementById("resetBut");
resbtn.onclick = function resetBut() {
document.getElementById("tixForm").reset();
document.getElementById("tiktype").reset();
document.getElementById("tikclass").reset();
document.getElementById("totalCost").innerHTML = "Total amount due: 0€";
}
What do you notice that is different from what you're doing?
https://code.sololearn.com/WPyzoehow03g/?ref=app
+ 3
Javascript was specifically designed to interact with and manipulate the HTML.
This topic is covered in the Javascript Intermediate course. The DOM (Document Object Model) represents the structure of a web page, starting from the body element and branching out to all the elements in any depth of nesting, kind of like a tree.
There are commands to find any specific html element inside the document, either by its tag, id, or even style (class). And you can create sibling elements and child elements with Javascript even without directly manipulating the innerHTML property (which is really a brutal intervention in the page structure, but sometimes can be useful).
You can learn about all these techniques in the Sololearn course.
+ 2
learn about insertAdjacentHTML
https://developer.mozilla.org/en-US/docs/Web/API/Element/insertAdjacentHTML