template & javascript questions
Hey, just a few questions:
1) with template tags, other than
template.content.cloneNode(true)
, is there anything else that you need to get familiar with regarding those? mdn just seems to show how to make the tag in html and that snippet there.
2) with template tags, what does shadowrootmode
do? and why is it useful?
3) what is the difference between .innerText
and .textContent
other than improved performance with .textContent
, and what use does each one have?
4) what is the main use for .append
?
Thanks in advance.11 Replies
1 - waaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaay too many to explain
also, mdn does show how to interact with those in js
2- no idea, but might be related to the default content inside of it
3-
innerText
inefficiently obliterates all the elements inside the tag, and sets the text
textContent
will remove the text node and replace it with a new text node, without changing anything else
4- to add something at the enddo you have the link? i can't find anything on mdn
is a "node" the content or the tag?
is there an opposite to
.append
to add something at the start?the "node" is everything in the dom
you can use
insertBefore
, but im not sure if prepend exists
ah, i just checked, i believe
prepend
exists
so what's the difference between elements and nodes? things such as .parentElement
and .parentNode
element refers to html element
node refers to node
it can be a comment, text, xml cdata and others
The only thing I know related to nodes is that when you select an element with
document.getElementById
and other document functions, it returns them as nodesall elements are nodes
but not all nodes are elements
Hm, so what nodes wouldn’t be elements?
text, comments, xml cdata and others
Ah okay, thank you for the help
you're welcome