

Put.js: CSS selector-based function for creating and manipulating the DOM - tilt
https://github.com/kriszyp/put-selector

======
neilk
It's an interesting idea but the notion of using a selector syntax as a
creation syntax seems to break down rather quickly.

Where xpath is loose, you end up being strict. For example the sibling syntax
creates two of something. But there's no syntax to make three. It might have
been better just to leave that out.

Also, the syntax to remove something is truly bizarre; you put() the negation.
Would it really be so bad to have another function, like remove() ?

Anyway I appreciate a totally different take on the problem here. A templated
approach seems like a cool idea. jQuery can be a little wordy when creating
structure, since their creation syntax simply is HTML, and if you want to make
it dependent on other data or ensure that data is well escaped then you end up
switching paradigms in the same line of code, e.g. $('<a>').attr( 'href', foo
);

~~~
Groxx
I think the 3x sibling would just be "td+td+td". I could be wrong about that
though, I haven't tried it out. Might have to, I find it _very_ interesting.

------
brian_c
I wrote something similar a while ago, mostly inspired by the various Zen
Coding plugins. Nice to be able to compare my approach with someone who knows
what they're doing.

You can play with mine here: <http://viewinglens.com/dojo-
modules/brian.util.create.html>

And the source: [https://github.com/brian-c/dojo-
modules/blob/master/brian/ut...](https://github.com/brian-c/dojo-
modules/blob/master/brian/util/create.js)

------
anm8tr
I agree that the removal syntax is unintuitive, but otherwise a truly
brilliant idea!

