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.

5th Nov 2023, 7:51 PM
Pizzapaul
3 odpowiedzi
+ 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
5th Nov 2023, 8:43 PM
Ausgrindtube
Ausgrindtube - avatar
+ 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.
6th Nov 2023, 4:46 AM
Tibor Santa
Tibor Santa - avatar
6th Nov 2023, 11:40 AM
Bob_Li
Bob_Li - avatar