Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>No, unfortunately, there is no such construct in JavaScript.</p> <p>You have a few different options, each with its own merits:</p> <ol> <li><p><h3>String concatenation</h3> :</p> <pre><code>var html = '&lt;div id="something"&gt;' + '&lt;p&gt;Lots of HTML&lt;/p&gt;' + '&lt;p&gt;Lots of HTML&lt;/p&gt;' + '&lt;p&gt;Lots of HTML&lt;/p&gt;' + '&lt;/div&gt;'; </code></pre></li> <li><p><h3>Escaping the <strong><code>newline</code></strong></h3>:</p> <pre><code>var html = '&lt;div id="something"&gt;\ &lt;p&gt;Lots of HTML&lt;/p&gt;\ &lt;p&gt;Lots of HTML&lt;/p&gt;\ &lt;p&gt;Lots of HTML&lt;/p&gt;\ &lt;/div&gt;'; </code></pre></li> <li><p><h3>Array joining</h3>:</p> <pre><code>var html = [ '&lt;div id="something"&gt;', '&lt;p&gt;Lots of HTML&lt;/p&gt;', '&lt;p&gt;Lots of HTML&lt;/p&gt;', '&lt;p&gt;Lots of HTML&lt;/p&gt;', '&lt;/div&gt;' ].join(''); </code></pre></li> <li><p><h3>Storing it in an arbitrary hidden element</h3>:</p> <p>HTML:</p> <pre><code>&lt;textarea id="template" style="display:none;"&gt; &lt;div id="something"&gt; &lt;p&gt;Lots of HTML&lt;/p&gt; &lt;p&gt;Lots of HTML&lt;/p&gt; &lt;p&gt;Lots of HTML&lt;/p&gt; &lt;/div&gt; &lt;/textarea&gt; </code></pre> <p>JavaScript:</p> <pre><code>var html = document.getElementById('template').value; </code></pre> <p>I prefer using <code>&lt;script type="text/html"&gt;</code>s or HTML comments but <code>&lt;textarea&gt;</code>s seem to be quite popular.</p></li> <li><h3>Using a full-on templating engine such as</h3>: <ul> <li><strong><a href="http://embeddedjs.com/" rel="nofollow noreferrer">http://embeddedjs.com/</a></strong></li> <li><strong><a href="http://jtemplates.tpython.com/" rel="nofollow noreferrer">http://jtemplates.tpython.com/</a></strong></li> <li>Also see: <strong><a href="http://ejohn.org/blog/javascript-micro-templating/" rel="nofollow noreferrer">http://ejohn.org/blog/javascript-micro-templating/</a></strong></li> </ul></li> </ol>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload