Advantages Of Putting HTML in Javascript

Posted by user1609376 on Stack Overflow See other posts from Stack Overflow or by user1609376
Published on 2012-09-09T21:12:47Z Indexed on 2012/09/09 21:38 UTC
Read the original article Hit count: 245

Filed under:
|
|

I am wondering if it is better to put your html in javascript or in your html files.

For example having my js file have this

$('<div>').addClass('test').append(
                        $('<p>').text('test1'),
                        $('<span>').text('test2'),
                        $('<span>').text('test3')
                      ).insertAfter( $('#test1') );

VS

My html file looking like this

<div id="#test1"></div>
<div class="test">
    <p>test1</p>
    <span>test2</span>
    <span>test3</span>
</div>

and the js file have:

$('.test').show();

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about jQuery