Today I Learned - Rocky Kev

TIL why you should always use textContent

POSTED ON:

TAGS:

Today I learned the difference between Node.textContent and all the others.

Versus HTMLElement.innerText.

Versus HTMLElement.innerHTML

var el = document.createElement('div');
el.innerHTML = 'A<p>B<span>C</span>D</p>D';
el.textContent; // "ABCDD" (HTML tags stripped successfully)

via the MDN
via https://stackoverflow.com/a/31466405/4096078


Related TILs

Tagged:

TIL why you should always use textContent

Today I learned the difference between 'Node.textContent'. It handles all elements, even hidden ones. It also prevents XSS attacks since it strips tags.

TIL prepend

When you're creating new elements in Javascript, you want to attach the new element to something that exists in the DOM already. You do that with append, and prepend.

TIL the simulating a Pipe function

It’s a pipe function that allows you to chain multiple operations together by taking a series of functions as arguments and applying them in a specific order to the input.