append () does not work in Internet Explorer

0

I have a code that collects data from a BD and dynamically introduces them to a page, so I create with jquery the elements and labels inside a "blank" page (it has some fixed data). In Chrome it works for me without any problem, it does not give any kind of error but, when I get to Internet Explorer, I get the following:

  

JavaScript runtime error: The object does not accept the 'append' property or method

I have to say that the same thing happens in Chrome from my mobile phone, I can not see the exception but it gives me an error too and the data is not shown.

var tr = document.createElement("tr");
tr.setAttribute("id", "1234");
$("table")[0].append(tr);

Those are the lines of code where it gives an error, exactly in the "append". I've been looking but I can not find anywhere that is a method not compatible with IE or mobile.

I do not think it is due to an error in another point of the code because, as I said, it works perfectly in chrome, and, since it is a very extensive code, I do not see it necessary to add more because I think it is one more question theoretical, but if a more "functional" example is necessary, I can do it.

EDIT

I add a simple example that I have not managed to work in IE either

$(document).ready(function() {
var tr = document.createElement("tr");
tr.setAttribute("id", "123");
$("table").append(tr);

var td = document.createElement("td");
td.setAttribute("id", "111");
tr.append(td);

td.innerText = "Fila1";
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<table></table>
    
asked by Rabegi 25.06.2018 в 18:47
source

1 answer

1

append is a function of jquery, to apply it to a document.createElement you have to "jqueryearlo" wave: $(tr).append(td);

or more vanilla tr.appendChild(td);

I leave you three options look which one works for you

$(document).ready(function() {
    var tr = document.createElement("tr");
    tr.setAttribute("id", "123");
    $("table").append(tr);

    var td = document.createElement("td");
    td.setAttribute("id", "111");
    tr.appendChild(td);
   
    td.innerText = "Fila1 col1";

    var td2 = document.createElement("td");
    td2.setAttribute("id", "111");
    td2.innerText = "Fila1 col2";
    $(tr).append(td2);

    

    $(tr).append($("<td>").html("Fila1 col3"));

    });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
    <table></table>
    
answered by 26.06.2018 в 10:00