I simply generate global functions corresponding to tags, so my stuff looks like this: div(span('hello world')).inject(document.body); Very simple to do and even simpler to use.
Many would frown upon polluting the global name space with functions corresponding to all known HTML tags.
Laconic: A Sane Method of Generating DOM Content in JavaScript
11–20 of 51 posts
Re: Laconic: A Sane Method of Generating DOM Content in JavaScript
#12This is pretty, but unfortunately the only performant way to generate dom elements in javascript is with HTML. HTML parsing is orders of magnitude faster in most browsers. How about a library like this to generate a string of HTML instead of dom elements?
Re: Laconic: A Sane Method of Generating DOM Content in JavaScript
#13This is really neat. The coolest part is being able to register your own "tags" which take any arguments you want. The problem I see is that this only works for "all known HTML tags." If you want to use custom tags, like (I believe that's what meteor uses), this won't cut it since it uses $.el.tagname syntax, every tag has to be loaded into the $.el object. How about a very similar, more jQuery-like syntax instead: $…
Though I did a poor job at documenting it, $.el is actually a function that accepts a tag name as the first parameter. The following two snippets are equivalent: $.el.div({className : 'foo'}); $.el('div', {className : 'foo'});
Re: Laconic: A Sane Method of Generating DOM Content in JavaScript
#14This is pretty, but unfortunately the only performant way to generate dom elements in javascript is with HTML. HTML parsing is orders of magnitude faster in most browsers. How about a library like this to generate a string of HTML instead of dom elements?
Re: Laconic: A Sane Method of Generating DOM Content in JavaScript
#15This is pretty, but unfortunately the only performant way to generate dom elements in javascript is with HTML. HTML parsing is orders of magnitude faster in most browsers. How about a library like this to generate a string of HTML instead of dom elements?
$.el.div($.el.span()).outerHTMLRe: Laconic: A Sane Method of Generating DOM Content in JavaScript
#16This is pretty, but unfortunately the only performant way to generate dom elements in javascript is with HTML. HTML parsing is orders of magnitude faster in most browsers. How about a library like this to generate a string of HTML instead of dom elements?
Like a template engine?
Re: Laconic: A Sane Method of Generating DOM Content in JavaScript
#17Re: Laconic: A Sane Method of Generating DOM Content in JavaScript
#18I much prefer CoffeeScript, because plain JS makes me mad, and CoffeeKup (http://coffeekup.org/) for generating DOM content.
Re: Laconic: A Sane Method of Generating DOM Content in JavaScript
#19This is pretty, but unfortunately the only performant way to generate dom elements in javascript is with HTML. HTML parsing is orders of magnitude faster in most browsers. How about a library like this to generate a string of HTML instead of dom elements?
While I don't entirely agree with your first statement, you could just grab the outerHTML instead of appending the element directly to the DOM: $.el.div($.el.span()).outerHTML
My first statement was certainly true in the previous generation of browsers, including IE 7. I'm not sure about more modern browsers. What basis do you have for disagreeing?
Refer to:
Re: Laconic: A Sane Method of Generating DOM Content in JavaScript
#20i don't understand the appeal of this when there's tons of client side js templating options (handlebars, jade, haml-js,...) that result in far more readable code than a $.el. prefixathon