Вопрос

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.

Это было полезно?

Решение

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

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top