I have a question, I use prototype, but maybe this question could apply to native javascript as well.
Which would be generally faster and more efficient to run:
$(divElement).insert('<div>Hello</div');
or
$(divElement).insert(new Element(div).insert('Hello'));
How about creating the element seperatly and assigning it to a variable like this:
var helloDiv = '<div>Hello</div>';
$(divElement).insert(helloDiv);
or
var helloDiv = new Element('div').insert('Hello');
$(divElement).insert(helloDiv);
Is creating inline html faster than creating an element and then inserting it? This information could be useful especially for constructing something like tables.
Thank you and appreciate your help.
It depends on the browser, its definitely true for ie and firefox but seems slower on chrome:
http://jsperf.com/innerhtml-vs-createelement-test.