Multiline string with JavaScript [duplicate]

1

I have a small string to display in JavaScript, but after much trying, I learned that if there is enter in the middle of the string snippet, it will not be displayed. Can anyone explain to me if there is a way to organize the code without making it impossible to display.

Follow the code below:

function outros(){
   var exibir;
   exibir = '<input type= "checkbox" name="st[]" value="Penicilina">Penicilina <br> <input name="st[]"  value="Contraste" type="checkbox">Contraste <br>';

   elexibir= document.getElementById('teste1');
   elexibir.innerHTML= exibir;
  }
    
asked by anonymous 21.11.2016 / 02:50

1 answer

2

You can use \ at the end to escape the line:

var suaString = "primeira linha \
                 segunda linha";

With ECMAScript 6 you can use this:

var suaString = 'primeira linha
                 segunda linha';
    
21.11.2016 / 02:58