ILovephp123 ILovephp123 - 1 year ago 106
HTML Question

Javascript Visible Element returning undefined

The HTML code that I'm trying to click is

<button type="submit" class="flatbutton">Send</button>


var i;
var button = document.getElementsByClassName("flatbutton");
for (i = 0; i < button.length; ++i) {
if (button[i].type == "submit") {
console.log(button[i].innertext);
}
}


For some reason, everything that is returned is undefined. This doesn't make sense, it should be returning "Send".

I'd prefer to only use Javascript and not JQuery

Answer Source

Simple typo in your code, innertext should be innerText

var i;
var button = document.getElementsByClassName("flatbutton");
for (i = 0; i < button.length; ++i) {
  if (button[i].type == "submit") {
    console.log(button[i].innerText);
  }
}
<button type="submit" class="flatbutton">Send</button>

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