+ 1
Web development: JavaScript in HTML
I know that in order to type JavaScript in html you need the script tag but I have been wanting to add equations in my website and found these documents and stuff. I am so confused about what are these documents and get element things
11 Respuestas
+ 2
Which documents and stuff?
+ 2
Do you have a code you're working which you can share? Perhaps someone can better help you if we can see what you're stuck with.
https://sololearn.com/compiler-playground/Wek0V1MyIR2r/?ref=app
+ 2
Wakhile Biyela
From your profile, I see that you are currently studying Javascript Intermediate.
Accessing and controlling html elements with javascript is explained in DOM & Events.
+ 1
I assume he means the document object
+ 1
That code works, great job! Now, if I understand correctly, you want to then include some equations? Can you give me an example of what you would like please?
+ 1
No i did not write that. AI did. Im here to understand what that thing is
+ 1
Wakhile Biyela
if you mean this:
function displayText(text) {
var outputBox = document.getElementById('output-box');
outputBox.innerHTML = text;
}
the 'document' refers to the html document.
It represents the html object part of your webpage that js needs in order to access the individual parts, like divs, p, tables, input boxes, id, classes, etc.
Here it is accessing the div element with the id='output-box' and assigning it to the variable outputBox:
var outputBox = document.getElementById('output-box');
Then it is replacing it's content with the text passed to the function displayText:
outputBox.innerHTML = text;
This function is called when either of the two buttons is clicked.
I would suggest using textContent instead of innerHTML:
outputBox textContent = text;
if you are not doing any fancy formatting, textContent has better performance because its value is not parsed as HTML.
0
Is that javascript intermediate? Cause im doing it
0
https://sololearn.com/compiler-playground/WFk8svV5qhMc/?ref=app. The thing is script
0
Wakhile Biyela this is the problem with using AI. It can spit out anything from anywhere but that doesn't mean you know what it's doing or if it's right, until you've learnt enough to know better.
What is it you aren't understanding? The JavaScript part in the <script> tags?
0
Okay im going to explain. There was something i wanted to do as a project so i asked AI to give me a basic framework so i can see what im doing and build up from there. Im not asking AI to build the whole thing just an example to reference. So i just wanted to know the documents thing only. I understand scripts