UserTMP101010 UserTMP101010 - 6 months ago 61
Javascript Question

Print content of element to console

I have a feed that is outputting content dynamically to an element. I want to take the text from element A and output it to the console log.


<div class="elementa">ID5667</div>

Console Output:

ID : ID5667

I've tried a few things, but I'm either getting undefined or the full HTML of that element.


I think below should work for you.

var result = document.getElementsByClassName("elementa")[0].innerHTML;


For more reference : getElementByClassName