What is the Dojo 1.6-equivalent jQuery (html)?

In jQuery, you can easily create DOM nodes from raw HTML. This is especially useful when using templates.

What is equivalent in Dojo?

(FYI: I am transferring something from jQuery to Dojo. Raw HTML is generated from Underscore.js templates, and I would like to avoid throwing them away.)


[UPDATE: 2012-01-19 7:17 pm GMT + 8] According to a comment by @esailija, Dojo.toDom is really the equivalent of jQuery (html) - unfortunately, it was only added in Dojo 1.7, while I got a bit stuck with Dojo 1.6. Updated question to reflect version.

+4
source share
2 answers

I think that maybe you are looking for a combination of dojo.place and dojo._toDom (available without underscore in> = 1.7).

The toDom function takes a string and turns it into a DOM element or document fragment.

 n = dojo._toDom("<li>foo</li>"); // n is a single DOM node n = dojo._toDom("foo"); // n is a DOM text node n = dojo._toDom("<li>foo</li><li>bar</li>"); // n is a DOM document fragment 

The place function also takes a string and a target.

 dojo.place("<li>foo</li>", dojo.byId("baz")); // li element is added to // element with id "baz" dojo.place("<li>foo</li>", "baz"); // Same as above. dojo.place("foo", "baz"); // Note: Element with id "foo" // is placed in element with // id "baz" dojo.place(dojo._toDom("foo"), "baz"); // Text node "foo" is placed // in element with id "baz" 

Pay attention to the third example: if the line does not start with < , it is considered as the identifier of an element somewhere else in the document.

Btw, the dojo.place function also takes a third-position argument, which can be "first", "last", "replace", "before", "after" (and possibly a few other things).

http://dojotoolkit.org/reference-guide/dojo/place.html

+6
source

This will be the create method.

+2
source

Source: https://habr.com/ru/post/1391814/


All Articles