Question

I don't like using innerHTML, even it's faster.

But, I need to convert html to dom manipulation code.

Ex)

<div class="my-class">
    <a href="#my-link">My Link</a>
</div>

to

var div = document.createElement('div');
div.className = 'my-class';

var a = document.createElement('a');
a.href = '#my-link';
a.appendChild(document.createTextNode('My Link'));
div.appendChild(a)

------ EDIT

I can't use jQuery because of mobile (especially android)

Was it helpful?

Solution

Based on your comments,

it seems you're seeking template framework (eg: check handlebars.js) But it is entirely different where your output will be different.

Here is a list Template-Engine-Chooser!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top