I'm having trouble retrieving the text of an HTML element.
var text_element = document.getElementById("details").getElementsByTagName("h3");
var text = text_element.innerText;
console.log(text_element);
console.log(text);
<div id="details">
<h3>Summary for</h3>
</div>
When I make the console call for text_element, I can actually see the h3object info, but when I call text I get undefined.
If I change the JS to be var text = text_element.innerHTML; I get the same, undefined.
Shouldn't I be getting the text inside the h3 element, Summary for instead of undefined?
Can anyone tell me what I'm doing wrong and what I need to do to fix it?
I am not using jQuery, this is strictly pure Javascript.
getElement S ByTagNameso you should writegetElementsByTagName("h3")[0]gEBTagNamereturns an ARRAY of matched elements...