0

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.

Community
  • 1
  • 1
Ally
  • 4,894
  • 8
  • 37
  • 45

1 Answers1

1

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

bhb
  • 2,476
  • 3
  • 17
  • 32
  • Looking for something where it can be any string of html, rather than a tag name. Probably should of been a bit more specific. Thanks for the reply though. – Ally Oct 09 '12 at 12:18
  • This does give me a good starting point on implementing a 'collection of elements create function' myself, was hoping something already existed in the closure framework though. – Ally Oct 09 '12 at 12:41