Multiline string with Javascript

Asked

Viewed 207 times

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 someone explain to me if there is a way to organize the code without disabling the display.

Follow the code:

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;
  }
  • @Guilhermenascimento gave a quick search and tmb had not found =]

  • 1

    @Brunno doesn’t need to delete her answer, in fact she has something else, about ES6 (which could be asked in the oldest question), but the tip I gave her is for future questions, I even doubled unintentionally, this is normal, the instruction there is even for the next times, now it’s up to you to restore or reply again :D, after all it’s quite interesting for the community.

1 answer

2


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

var suaString = "primeira linha \
                 segunda linha";

With Ecmascript 6 you can use it like this:

var suaString = `primeira linha
                 segunda linha`;
  • 1

    An example with your code =]

  • This has already been asked in http://answall.com/q/4000/3635 and http://answall.com/q/88330/3635, I recommend to search if there is already an answer and mark the question as duplicate instead of answering, because if there will be several repeated and scattered contents.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.