Hacker News new | ask | show | jobs
by jarek-foksa 5236 days ago
The idea that CSS selectors could be used for element creation is awesome. It would be so convenient to write:

    var link = el("a#top.link[src='http://google.com'][data-external='true']")
Instead of:

    var link = document.createElement('a');
    link.setAttribute('id', 'top');
    link.setAttribute('class', 'link'); 
    link.setAttribute('src', 'http://google.com');
    link.dataset.external = 'true'
Someone needs to bring it to W3C forums, otherwise we might end up with this http://lists.w3.org/Archives/Public/www-dom/2011OctDec/0020....
1 comments

I get that what you're trying to do is keep it syntactically correct javascript, but just in case, have you looked at HAML [1] and/or Jade[2]? Both templating languages that allow you to write HTML in that kind of way. Even less syntax than what you're writing there.

I guess you have the overhead of the template language and rendering them though still.

[1] http://haml-lang.com/

[2] http://jade-lang.com/

EDIT: Added links.

What I'm looking for is a way to easily create single DOM nodes, not a full templating language.

HAML and Jade assume that you have static pseudo-markup defined upfront and you just fill it with data, this approach is not suitable for apps that are doing heavy DOM manipulations (e.g. SVG editor, text editor, sophisticated widget toolkit).