Opened 11 years ago

Closed 11 years ago

#7063 closed enhancement (fixed)

[patch][cla] Add method to reference single items in a NodeList

Reported by: guest Owned by: dante
Priority: high Milestone: 1.2
Component: Core Version: 1.1.1
Keywords: NodeList Cc:
Blocked By: Blocking:

Description

I often find myself wanting to work with a single item in a NodeList? but without losing all the wonderful features of the NodeList?. For example, to connect to a click event for a single item, you have to do something like:

dojo.connect(dojo.query("...")[2], "onclick", ...);

I suggest adding a method, maybe named at, items, or get (a la jQuery) that would take a list of indices and return them as a new NodeList?. It's sort of like slice but not quite. Some examples...

Add a click handler to the first paragraph:

dojo.query("p").at(0).onclick(...);

Do something with the 3rd, 5th and 9th paragraph:

dojo.query("p").at(3,5,9).forEach(...);

Attachments (1)

NodeList-at.diff (1.5 KB) - added by guest 11 years ago.
Patch to add "at" method --D. Schontzler

Download all attachments as: .zip

Change History (3)

Changed 11 years ago by guest

Attachment: NodeList-at.diff added

Patch to add "at" method --D. Schontzler

comment:1 Changed 11 years ago by dylan

Milestone: 1.2
Owner: changed from anonymous to dante
Summary: Add method to reference single items in a NodeList[patch][cla] Add method to reference single items in a NodeList

comment:2 Changed 11 years ago by dante

Resolution: fixed
Status: newclosed

(In [14594]) fixes #7063 - add an .at() method to NodeList? to select small subsets of NodeList?'s as a new NodeList? - cla on file for Schontzler, David ... thanks!

Note: See TracTickets for help on using tickets.