What is the best way to have long string literals in Javascript?

Possible Duplicate:
Multiline Strings in Javascript

In Ruby you can do something like this

temp = <-SQLCODE select * from SQLCODE users

Thus, you have a very long string literal in your code, you do not need to avoid a lot of characters. Is there something similar in JavaScript?

I currently have javascript code similar to this and its driving me nuts ...

  new Element.update(lightbox_id, " \
    <div id='overlay' class='overlay' > \
    </div> \
    <div id='lightbox' class='lightbox'> \
      <div class='lightbox_title'> \
        <div class='corner_image' onclick=\"close_lightbox();return false;\"><a href='#' >" + corner_image + "</a></div> \
        <div class='lightboxname' id='lightboxname'>" + title + "</div> \
        <div class='close_image'> \
          <a href='#' onclick=\"close_lightbox();return false;\">Close</a> or Escape key\
        </div> \
      </div> \
      <div id='" + lightbox_content_id + "' class='lightbox_content'>    \
      </div> \
      <script>  \
        watch_for_escape(); \
      </script> \
    </div> \
");
+3
source share
3 answers

The syntax you refer to is often called a document here (or HEREDOC) , and no, it is not available in Javascript.

, , JavaScript.

+5

html inline , , :

div html, , - {title}. yourdiv.innerHTML.replace(...

+2

Rails, rjs div HTML:

page.replace__html 'lightbox_id', :partial => 'overlay'

overlay.html.erb html .

, "overlay" , , .

0
source

Source: https://habr.com/ru/post/1708870/


All Articles