Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Ticket #4669 (closed enhancement: fixed)

Opened 2 years ago

Last modified 2 years ago

[PATCH] Add getElementsByClassName and getElementsBySelector to Element.Methods

Reported by: blog@andrewdupont.net Assigned to: sam
Priority: normal Milestone:
Component: Prototype Version:
Severity: normal Keywords:
Cc: rubyonrails@andrewdupont.net

Description

I've always found it awkward to call document.getElementsByClassName within a certain page context. Now that we've got Element.extend, we don't really need the awkward syntax of specifying the context in the second argument.

This patch adds two new methods to Element.Methods. The first lets you do $('container').getElementsByClassName('item') instead of document.getElementsByClassName('item', $('container')).

The second lets you replicate the $$ function within the children of a particular element. Instead of $$('#container p.item'), you can do $('container').getElementsBySelector('p.item'), which is handy when you're grabbing an element programmatically (or one that can't be uniquely identified by a CSS selector).

Sorry for not including test cases -- I'll add them as soon as I get the time.

Attachments

elementmethods.patch (1.1 kB) - added by blog@andrewdupont.net on 04/09/06 20:13:16.
Patch described above (I'm on Windows, but I think the newlines are Unix-flavored)
elementmethods_src.patch (1.1 kB) - added by blog@andrewdupont.net on 04/09/06 20:36:42.
Diffed against dom.js rather than prototype.js
elementmethods_test.patch (1.6 kB) - added by blog@andrewdupont.net on 04/09/06 21:01:55.
Unit tests

Change History

04/09/06 20:13:16 changed by blog@andrewdupont.net

  • attachment elementmethods.patch added.

Patch described above (I'm on Windows, but I think the newlines are Unix-flavored)

04/09/06 20:36:42 changed by blog@andrewdupont.net

  • attachment elementmethods_src.patch added.

Diffed against dom.js rather than prototype.js

04/09/06 21:01:55 changed by blog@andrewdupont.net

  • attachment elementmethods_test.patch added.

Unit tests

04/11/06 01:41:25 changed by Andrew Dupont <rubyonrails@andrewdupont.net>

  • cc set to rubyonrails@andrewdupont.net.

08/30/06 16:14:32 changed by sam

  • status changed from new to closed.
  • resolution set to fixed.

(In [4876]) prototype: Add Element.Methods.getElementsByClassName and Element.Methods.getElementsBySelector. Closes #4669.