How do I apply javascript to html


#1

This is the biggest mystery ever since my journey to javascript. I know how to link javascript to html, much like css, but I don't know exactly to use it. For example, with html and css if i make an html file, I can then create a css file, target specific tags etc to make it look aesthetically pleasing. Do I do the same for javascript? I understand the concept of an array, function, object, method etc...but how do I apply that with my html and I'm not wanting to know how to link js file to html?Pardon me if I didn't use the proper terminologies, but I hope my answer make sense.


#2

it makes perfect sense what you are asking, what you are looking for is DOM manipulation using JS, which isn't covered in the JS course on codecademy

mdn - textContent
mdn - innerHTML
mdn - getElementById


#3

:astonished: this is exactly what I wanted to know. I've been researching and posting questions all over the place , for the answers I either get how to link js file to html or nobody understands what I'm talking about. Thank you so much!


#4

mdn - getElementByClassName
mdn - getElementByTagName
mdn -addEventListener
mdn - documentfragemnt

There are plenty of functions to manipulate DOM, and jquery is made to make DOM manipulation easier

The documentfragment is useful if you need to do multiply DOM manipulation, manipulating the DOM is expensive (resource wise), so then creating a documentFragment first saves processing power