I have been trying to get the text from a div using only javascript.
I started with jQuery using the following code:
var divText = $("div.Xr3").html();
Then for my JavaScript I tried:
var divText = document.getElementsByClassName("Xr3").innerHtml;
Which returns undefined. How can I accomplish this using JavaScript only?
getElementsByClassNamereturns a live array of HTML elements, so you can’t accessinnerHTMLdirectly like this. You will either have to loop over its results, or if you know there’s only one, apply[0]to it before accessinginnerHTML.or, in a single-element scenario,