Skip to content Skip to sidebar Skip to footer

.innerhtml
Breaking

Why is this breaking? I've not used .innerHTML correctly before and don't know why this would be wrong. function asdf() { document.getElementById('qwerty').innerHTML='A

Solution 1:

You have to escape new-lines in JavaScript string-literals:

functionasdf() {
    document.getElementById("qwerty").innerHTML="A<br>\
      B<br>\
      C<br>\
      D<br>";
}

Though you could, potentially more-easily, simply insert newlines in the string itself:

functionasdf() {
    document.getElementById("qwerty").innerHTML = "A<br>\nB<br>\nC<br>\nD<br>";
}

Solution 2:

Javascript string literals cannot contain newlines.

You can escape the newlines with backslashes:

var myString = "a\
b";

Post a Comment for ".innerhtml
Breaking"