Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How To Append (Or Other Method) a Lot of HTML Code?

I need to append a lot of HTML code. To improve readability, I don't want to write that all in one line, but split them as regular HTML. That would be like 15 new-lines or something. The problem is that JavaScript doesn't allow me to do that.

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 in that place.

I need to add some variables too.

like image 983
daGrevis Avatar asked Jul 01 '11 09:07

daGrevis


2 Answers

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

or

    target.append(' <div class="replies">\
            <p>...</p>\
            <img src="" alt="" />\
        </div>'
    );
like image 107
Kanishka Panamaldeniya Avatar answered Oct 07 '22 07:10

Kanishka Panamaldeniya


Creating multiline strings in JavaScript

like image 30
jcomeau_ictx Avatar answered Oct 07 '22 06:10

jcomeau_ictx