UserTMP101010 UserTMP101010 - 1 year ago 111
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.

Answer Source

I think below should work for you.

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


For more reference : getElementByClassName

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download