Re: [whatwg] getElementsByClassName()

2006-02-07 Thread Ric Hardacre



Dean Edwards wrote:

Jim Ley wrote:

That is not immediately apparent, and neither is it apparent that a
classname specific shortname is worthwhile when a CSSSelector one
would be more appropriate.You don't continually add methods,
methods are complexity, they need writing, they need testing etc.  you
have to have a reason to add a method.



A good API should expose a meaningful interface to its consumer. If we 
are allowed to define data according to a skew on its structure (HTML 
className) then the interface to that data should reflect this.


The getElementsByClassName() method has already been compared to the 
getElementsByTagName() and getElementById() methods. "class" is another 
way to slice the data. It is a core part of HTML, the language we are 
extending.


To me, getElementsByClassName() is a missing feature of the DOM to 
support HTML4. I'd be happy if that were fixed in HTML5.




I think this is a very clear explanation of the reasons to include it, 
it's not as if we're discussing GetElementsByOnMouseOver() here. But 
let's throw out a use case off the top of my head:


i'm making a shopping cart and each product has a checkbox next to it, 
to select it for deletion, there are also other checkboxes on the page, 
one to agree to the terms, another to sign up for the mailing list, 
another to sign up for "advertisements from our business partners", 
another one up at the top right by a search box for a search option and 
finally the "select all for deletion" checkbox. when i click on the 
latter i want to check all the individual checkboxes for each product. 
as they're in the basket i'm specifically styling them class="prodchck". 
so to check them all all i need to do is:


function checkall()
{
var a = document.getElementsByClassName("prodchck");
for( var i = 0 ; i < a.length ; i++ )
a[i].checked = true;
}




Re: [whatwg] getElementsByClassName()

2006-02-07 Thread BÁRTHÁZI András

Hi,

James Graham wrote:

Lachlan Hunt wrote:

James Graham wrote:
Also I would be surprised if there weren't multiple implementations 
of getElementsByClassname floating around in javascript libraries. So 
you can't really call it unimplemented.


While there are many JavaScript implementations (I even wrote one 
myself a few months ago), all the custom JS implementations count for 
exactly zero native implementations in UAs, which is what really counts.


But it suggests that its not hard to implement, which was my (poorly 
made) point.


It's not hard to implement in JavaScript, but there's no an effective 
way to do it. You have to get all the elements of the page, and then 
check each if it has a specific className. And if you want to do it in 
the right way, you have to split clssNames by spaces, and then check, if 
it meets with the specified className.


Bye,
  Andras