I am working on Google Tag Manager and I am having trouble getting the outerHTML text.
<div class="a"><i class="b"></i> email </div>
I tried multiple ways but I can't get it to work.
document.querySelector("div.a").outerHTML;
document.querySelector("div.a").outerHTML.textContent;
console.log(document.querySelector("div.a").outerHTML);
console.log(document.querySelector("div.a").outerHTML.textContent);
<div class="a"><i class="b"></i> email </div>
Here is the documentation on
Node.textContent: https://developer.mozilla.org/en-US/docs/Web/API/Node/textContentIn the snippet below, notice that
.textContentincludes the leading/trailing spaces, whereas.innerTextdoes not