W3C home > Mailing lists > Public > whatwg@whatwg.org > February 2006

[whatwg] getElementsByClassName()

From: Michel Fortin <michel.fortin@michelf.com>
Date: Fri, 3 Feb 2006 11:14:44 -0500
Message-ID: <DA7D2010-47D0-46DB-B003-6C92E6085871@michelf.com>
Le 2006-02-03 ? 09:30, Jim Ley a ?crit :

> Yes, but they're all using it to attach events to every one of the
> class, which is why you have to look at use cases, the reason they're
> doing it is not because getElementsByClassName is missing, but because
> addEventListenerToClass or -moz-binding etc. are missing.
>
> It's the classic mistake of looking at making the workarounds easier,
> when you should be looking at making the underlying use easier.

I have been following this list for sometime and did not have much to  
say until now. But I have a use case for this function which cannot  
work by simply using addEventListenerToClass. And that's a real  
working use case for a web application I'm working on, nothing  
hypothetical.

I have a some markup like this:

     <ul>
         <li><a href="#tab1">Tab 1</a></li>
         <li><a href="#tab2">Tab 2</a></li>
     </ul>

     <div id="tab1" class="pane">
         ...
     </div>

     <div id="tab2" class="pane">
         ...
     </div>

With the help of a style sheet, the script transforms this into some  
sort of tab view. It search for each div of class "pane". It looks  
for links pointing to each of these div elements and attach an event  
to each so that when you click on the link it shows the pane (and  
hides other panes).

  - - -

So to generalize the use case, when I want to attach an event to a  
child element or an element linked by any other mean to the element  
having that class, I can't use addEventListenerToClass.

Now, with that particular example in mind, something like  
getElementsByHref('tab1') could be useful too, but surely you can't  
have a function for each html attribute.


Michel Fortin
michel.fortin at michelf.com
http://www.michelf.com/
Received on Friday, 3 February 2006 08:14:44 UTC

This archive was generated by hypermail 2.3.1 : Monday, 13 April 2015 23:08:26 UTC