[thelist] Javascript Class Selector

VOLKAN ÖZÇELİK volkan.ozcelik at gmail.com
Sun Jan 14 10:34:30 CST 2007


Hi Bob,

It's a common need among DOM developers.

s at rdalya [1] has DOMManager.getElementsByClassName [2] specially crafted for
that:

_this.getElementsByClassName=function(strClassName,elmParentNode)
{
    var children=null,
        i=0;
        result=[];

    elmParentNode=(elmParentNode)?_.o(elmParentNode):document.body;

    children=elmParentNode.getElementsByTagName("*");

    for(i=0;i<children.length;i++)
    {
        if(children[i].className.match(new RegExp("(^|\\s)"+
            strClassName+"(\\s|$)")))
        {
            result.push(children[i]);
        }
    }

    return result;
};

it's not rocket science and most of the libraries out there (prototype, dojo
etc) has the same functionality built in.

But what you need is simply get an element by class name the function above
will be okay.
No need to use a rocket launcher to kill a fly on the wall ;)

By the way I've removed commercial pricing limitations from s at rdalya. [3]
(many thanks to those who have purchased it a priori. And many thanks to
google ads :) )

For those who are interested I'll replace the current license with a fairly
generous LGPL and continue my development of the API at
sourceforge.net(should they accept my registratin)

I think you understand that it's a hard decision / transition period for me,
because there are users of s at rdalya who have purchase a commercial license
and been using the framework actively on their applications. I have nothing
but a big thank you to offer to them (and I believe most of them will want a
refund rather than a full-hearted "thank you" message).

Anyway, I've made up my decision and will move along my way no matter what.

[1] http://www.sarmal.com/sardalya
[2] http://sardalya.pbwiki.com/DOMManager
[3] http://www.sarmal.com/sardalya/Commercial.aspx

HTH,
-- 
Volkan Ozcelik
+>Yep! I'm blogging! : http://www.volkanozcelik.com/cre8/blog/
+> Going solo in Turkish: http://www.volkanozcelik.com/donkisot/
+> My projects/studies/trials/errors : http://www.sarmal.com/
+> Sardalya JavaScript Library: http://www.sarmal.com/sardalya/



More information about the thelist mailing list