javascriptprocessmaker

Javascript separate string with enter


I want to put html script inside of <div id>, but I can't separate the string with enter. So I put the code like this (example):

var html = "<table style='width:100%'><tr><th>Firstname</th><th>Lastname</th><th>Age</th></tr>";

$("#panelChatlog").html(this.html);

as you can see the string is html code, but I want to separate html code so it's more readable like this:

var html = "
          <table style="width:100%">
            <tr>
              <th>Firstname</th>
              <th>Lastname</th>
              <th>Age</th>
            </tr>
        ";

$("#panelChatlog").html(this.html);

But it is impossible in my javascript. I am using processmaker 3.x Any advise?


Solution

  • This is what the ` was character introduced for, so you don't need to manually write \n in your strings. Just replacing the quotes is sufficient (make sure to close out your table tag):

    var html = `
              <table style="width:100%">
                <tr>
                  <th>Firstname</th>
                  <th>Lastname</th>
                  <th>Age</th>
                </tr>
              </table>
            `;
    
    alert(html);