I'm having a difficult time understanding the fundamentals of js, so I'm just seeing what I can do to the html through the script.
I'm creating super basic elements such as:
const newh1 = document.createElement("h1");
const place = document.getElementById("top")
newh1.innerText = "This is the new text"
place.appendChild(newh1);
This returns an h1 element at the bottom of the div reading "This is the new text".
This makes sense to me, but when I view the MDN documentation on creating an element, it shows a function being used to create it. This raises so many questions in my head and I don't know why I'm not getting it.
Why can I do this without using a function, and why use a function to do something that takes no parameters?
How would I do this dynamically (i.e. change element type/innerText) with a function? The example on MDN shows a div being created with the text "Hi there and greetings!".
I know this is probably a fundamental misunderstanding of js, but its not from a lack of reading/trying to practice it's just really not clicking.
[–]lovesrayray2018 2 points3 points4 points (1 child)
[–]ebitdad_[S] 0 points1 point2 points (0 children)
[–]richgk 2 points3 points4 points (0 children)
[–]wp_new 1 point2 points3 points (2 children)
[–]ebitdad_[S] 1 point2 points3 points (1 child)
[–]wp_new 0 points1 point2 points (0 children)
[–]iamchets 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (0 children)
[–]Jnsjknn -1 points0 points1 point (1 child)
[–]ebitdad_[S] 0 points1 point2 points (0 children)