+ 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

13th Feb 2024, 2:26 PM
Wakhile Biyela
Wakhile Biyela - avatar
11 Respuestas
+ 2
Which documents and stuff?
13th Feb 2024, 3:09 PM
A͢J
A͢J - avatar
+ 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
14th Feb 2024, 8:52 AM
Ausgrindtube
Ausgrindtube - avatar
+ 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.
15th Feb 2024, 6:49 AM
Bob_Li
Bob_Li - avatar
+ 1
I assume he means the document object
13th Feb 2024, 3:12 PM
Toni Isotalo
Toni Isotalo - avatar
+ 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?
14th Feb 2024, 2:45 PM
Ausgrindtube
Ausgrindtube - avatar
+ 1
No i did not write that. AI did. Im here to understand what that thing is
15th Feb 2024, 4:32 AM
Wakhile Biyela
Wakhile Biyela - avatar
+ 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.
15th Feb 2024, 9:44 AM
Bob_Li
Bob_Li - avatar
0
Is that javascript intermediate? Cause im doing it
13th Feb 2024, 3:46 PM
Wakhile Biyela
Wakhile Biyela - avatar
14th Feb 2024, 9:13 AM
Wakhile Biyela
Wakhile Biyela - avatar
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?
15th Feb 2024, 7:59 AM
Ausgrindtube
Ausgrindtube - avatar
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
15th Feb 2024, 8:15 AM
Wakhile Biyela
Wakhile Biyela - avatar