0

guys! I want to know, what's difference between

var newDiv = createElement("div");
someElement.innerHTML(newDiv);

and

var newDiv = "<div></div>";
someElement.innerHTML(newDiv);

What kind of profit will I get? If i want to add big piece of code, i have to create all elements and wrap them one another?

In case, when i have many nest-levels

<div>
  <article class="article">
      <header class="article-top">
           <h1 class="article__title">%title%</h1>
      </header>
      <div class="article-body">
         <p>
            %body%
         </p>
      </div>
  </article>
</div>    

I see it in other frameworks, as react and etc.

I guess, that i'm wrong, but i need help :)

j08691
  • 204,283
  • 31
  • 260
  • 272
Borisov Semen
  • 448
  • 5
  • 8
  • The first one will not work since it should be `document.createElement("div");`.. One difference. Also, you get an DOM object that you can continue working with in the first case (If written correctly). In the second you only have a string. – Arg0n Nov 28 '15 at 18:23
  • Btw, in jQuery, you can do `var el = $("
    ");` and still get an object you can work with.
    – Arg0n Nov 28 '15 at 18:29

0 Answers0