What is the difference between innerHTML & innerText? | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
0

What is the difference between innerHTML & innerText?

Which is better to use?

22nd Oct 2021, 9:36 AM
Fź«€ā²…įƒ«į„†ĶŸį„™į„‰įƽ
Fź«€ā²…įƒ«į„†ĶŸį„™į„‰įƽ - avatar
2 Respostas
+ 2
innerText does not render HTML tags, innerHTML does. Be careful when you update an element's innerHTML with values from user inputs, even indirectly.
22nd Oct 2021, 9:50 AM
Ipang
+ 2
innerText: Retrieves and sets the content in plain text. We can not insert the HTML tags. It ignores the spaces. It returns text without an inner element tag. innerHTML: Retrieves and sets the content in HTML format. We can insert the HTML tags. It considers the spaces. It returns a tag with an inner element tag.
22nd Oct 2021, 9:50 AM
Omkar Kamat
Omkar Kamat - avatar