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
ἔρως
ἔρως3mo ago
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 end
snxxwyy
snxxwyyOP3mo ago
do 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?
ἔρως
ἔρως3mo ago
the "node" is everything in the dom you can use insertBefore, but im not sure if prepend exists
snxxwyy
snxxwyyOP3mo ago
ah, i just checked, i believe prepend exists so what's the difference between elements and nodes? things such as .parentElement and .parentNode
ἔρως
ἔρως3mo ago
element refers to html element node refers to node it can be a comment, text, xml cdata and others
snxxwyy
snxxwyyOP3mo ago
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 nodes
ἔρως
ἔρως3mo ago
all elements are nodes but not all nodes are elements
snxxwyy
snxxwyyOP3mo ago
Hm, so what nodes wouldn’t be elements?
ἔρως
ἔρως3mo ago
text, comments, xml cdata and others
snxxwyy
snxxwyyOP3mo ago
Ah okay, thank you for the help
ἔρως
ἔρως3mo ago
you're welcome
Want results from more Discord servers?
Add your server