این محتوا تنها در این زبانها موجود است: English, Español, Français, Italiano, 日本語, 한국어, Русский, Türkçe, Українська, 简体中文. لطفاً به ما
createTextNode vs innerHTML vs textContent
اهمیت: 5
We have an empty DOM element elem
and a string text
.
Which of these 3 commands will do exactly the same?
elem.append(document.createTextNode(text))
elem.innerHTML = text
elem.textContent = text
Answer: 1 and 3.
Both commands result in adding the text
“as text” into the elem
.
Here’s an example: