The Prototype JS API documentation mentions the $$()
function, which allows you to select and extend elements based on CSS selectors, like the $()
function in jQuery does.
However, on that page, $$
is presented like some sort of last resort:
Sometimes the usual tools from your DOM arsenal just aren't enough to quickly find elements or collections of elements. If you know the DOM tree structure, you can simply resort to CSS selectors to get开发者_如何学C the job done.
Why is that? Should I stay away from $$
and just use document.getElementsByClassName
(ugh) instead?
Based on that quote you wrote, I'd say they are encouraging you to use $$()
. $$()
offers you a cross-browser way to access elements quickly and easily. On the other hand, document.getElementsByClassName()
is either buggy or not functional in IE version up to and including version 8.
In a complicated project, I try to stay away from using $$()
so that I don't accidentally select something I don't want. For a smaller project, I wouldn't worry. I can usually accomplish what I need to with $(Element).childElements
or $(Element).immediateDecendants
instead.
精彩评论