Question

Possible Duplicate:
Closure library dom node from html text

in jQuery you can create a dom element like this

var domElement = $("<div><p>more tags and html</p></div>");

How do you do the same in Google Closure?

I don't want to have to include the whole jQuery library for something that seems to minimal.

Was it helpful?

Solution

From the document

goog.dom.createElement(name); //creates a new element
goog.dom.createDom(tagName, opt_attributes, var_args) //Returns a dom node with a set of attributes.

Try(untested code):

 var p = goog.dom.createElement('p');
 p.innerHTML = "abc";
 var div =  goog.dom.createDom('div', null, p);

I know its not as elegant and clean as jquery :)

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