Domanda

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.

È stato utile?

Soluzione

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 :)

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top