Why need JavaScript to write a paragraph or remove elements, attributes, etc? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Why need JavaScript to write a paragraph or remove elements, attributes, etc?

In few SL lessons, I saw this case where JS is used to write paragraph & remove or add elements, attributes. What is the main purpose of this? Because I know if I want to remove or add anything like this, I can do it directly in the HTML tags

4th Aug 2018, 11:11 PM
Jerry Okugbe
Jerry Okugbe - avatar
3 Answers
+ 6
For example, you have a website. You have a button that adds or removes a paragraph in an article when clicked. Now, when thousands of users accessed your website all at the same time and clicked that button, can you add or remove that paragraph manually in HTML tags for each request? There comes JavaScript. It can do it dynamically with optimal reliability and speed under normal circumstances.
4th Aug 2018, 11:38 PM
Jonathan Pizarra (JS Challenger)
Jonathan Pizarra (JS Challenger) - avatar
+ 2
Thanks guys! I'm grateful for this🙏🙏
5th Aug 2018, 2:03 PM
Jerry Okugbe
Jerry Okugbe - avatar
+ 1
You can edit static contents by modifying HTML tags, but not dynamic ones. Not really HTML based, we can still use SoloLearn as an example. For every question you asked, the app will also display duetime and your username. At the time of writing code, it is not possible to know the how many question will be created, at which time, by whom. This is generated on runtime, which requires JS to do so.
4th Aug 2018, 11:40 PM
Hoàng Nguyễn Văn
Hoàng Nguyễn Văn - avatar