How to add (or another method) a lot of HTML code?

I need to add a lot of HTML code. To improve readability, I donโ€™t want to write everything on one line, but break them down like plain HTML. It will be like 15 new lines or something like that. The problem is that JavaScript does not allow me to do this.

var target = $('.post .comment_this[rel="' + comment_id + '"]').parent().parent(); target.append(' <div class="replies"> <p>...</p> <img src="" alt="" /> </div> '); 

Basically, I need to add HTML to this place.

I also need to add some variables.

+6
source share
6 answers
  target.append(' <div class="replies">'+ '<p>...</p>'+ '<img src="" alt="" />'+ '</div>' ); 

or

  target.append(' <div class="replies">\ <p>...</p>\ <img src="" alt="" />\ </div>' ); 
+8
source
 target.append(' ?> <div class="replies"> <p>...</p> <img src="" alt="" /> </div> <?'); 

Separate html and php with close / open php tags and it should work fine. when adding var to html just use tags again, for example: <? $hello ?> <? $hello ?>

+1
source

If you want to insert variables into html you can use some template library like jQuery.template

0
source

As of 2015, ECMA 6 you can do this:

 target.append(` <div class="replies"> <p>...</p> <img src="" alt="" /> </div> `); 
0
source

use html () instead of append

 target.html('<div class="replies"><p>...</p><img src="" alt="" />,</div>'); 
-1
source

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


All Articles