IE: Invalid target element - add table using innerHTML + string

In Internet Explorer, this line document.getElementById("left").getElementsByTagName("tbody")[0].innerHTML = document.getElementById("left").getElementsByTagName("tbody")[0].innerHTML + string;gives meSCRIPT600: Invalid target element for this operation. …character 10

A string is just one that contains a set of pills. This works great in Chrome, Safari or Firefox. Is there a better way to do this? What I am doing is when the user gets to the bottom of the page, I add plates to the table to load more content. This is a kind of AJAX endless scrollable transaction type - the client requested. I am using Javascript and would rather stay with Javascript at this point and not change jQuery just for this task.

Update the same: document.getElementById("left").innerHTML = document.getElementById("left").innerHTML + string; Also, there is a left<table id="left">

+5
source share
2

, :

var div = document.createElement("div");
div.innerHTML = "<table><tbody>" + string + "</tbody></table>";

document.getElementById("left")
  .appendChild(div.firstChild.tBodies[0]);
+4

, . , . <tr> html.

if (document.attachEvent) { //if using old IE
    var currentTable = document.querySelector("#myTable");
    var currentTableHTML = currentTable.outerHTML;

    //replace closing tag with new code + closing tag
    currentTableHTML = currentTableHTML.replace("</tbody>", html + "</tbody>";

    currentTable.parentNode.removeChild(currentTable);

    //reinsert the table before some other element - you can use something else if you have a container for the table
    document.querySelector("#someElement").insertAdjacentHTML("beforebegin", currentTableHTML);
}
else {
    //use insertAdjacentHTML in a normal browser
}
0

All Articles