Search code examples
javascripthtmlfunctionhtml-tableconcatenation

Invalid left-hand side in assignment while concatenating


function nowakolumna(){
    document.getElementById("listacen") += '<tr><td><input type="text"></td><td><input type="text"></td></tr>';
}

i have this code for adding new column in table but when i try to execute it via button with onclick listener i get this error: Invalid left-hand side in assignment. Anyone help.


Solution

  • You cannot do that. Operator += on a document element object is not defined. You have to do this:

    function nowakolumna() {
        document.getElementById("listacen").innerHTML += '<tr><td><input type="text"></td><td><input type="text"></td></tr>';
    }