Opened 12 years ago

Closed 12 years ago

#9431 closed enhancement (wontfix)

Simplify creating a node list from a node

Reported by: Les Owned by: anonymous
Priority: high Milestone: tbd
Component: General Version: 1.3.0
Keywords: NodeList Cc:
Blocked By: Blocking:


Currently, when I want to create node list from a node I need to write:

var nl = new dojo.NodeList(dojo.byId("foo"));

This is too verbose IMO. Creating a node list should be much simpler, e.g.

var nl2 = dojo("foo");

Change History (4)

comment:1 Changed 12 years ago by alex

A simpler form is already available:

var nl3 = dojo.query("#foo");

comment:2 Changed 12 years ago by James Burke

More info:

You can do:

var nl1 = dojo.query("#foo");

Or, if you already have a node,

var nl2 = dojo.query(nodeRef);

If you like, you can create your own alias too:

function $() {
    return dojo.query.apply(dojo, arguments);

var nl3 = $("#foo");

I like the idea of having a dojo() function, but I think it should map to the general dojo namespace and not just a wrapper around dojo.query/NodeList. I describe that a bit in this post:

Does one of the above examples work for you?

comment:3 Changed 12 years ago by dante

also, you might find dojo.node("foo") useful/concise:

(note: it is not 1:1 with NodeList? api's, nor is it completely unit tested, just thought I'd pass it along. The returned element is a decorated version of the node with NodeList?-like api's attached (minus .forEach and other array methods))

we'd discussed the possibility of making dojo a function decorated with the APIs, but discarded it as too much magic, and as james points out should not be limited to query, disregarding all the other useful functions.

also dojo.conflict() in plugd gives you $("#f00") as a NodeList? instantiation, among other things.

comment:4 Changed 12 years ago by dante

Resolution: wontfix
Status: newclosed

not in 1.x at least. The available options must suffice. we can't overload dojo to be a fn like this now.

Note: See TracTickets for help on using tickets.