How to Retrieve All Inner HTML with Same Class Name in JavaScript

Inner HTML

If you want to retrieve all inner html in multiple <span> with same class name, here is an example:

...
  var msg_array = document.getElementsByClassName("info");
  var message = "";
  for (var i = 0; i < msg_array.length; i++) {
    message += msg_array.item(i).innerHTML;
    message += "\n";
  }
  if (message != "")
    alert(message);
  }
...

Note that, we add a line break character after every element for formatting the output message.

Leave a Reply

Your email address will not be published. Required fields are marked *