On 17 Oct 2007, at 04:50, Chris Knowles wrote:

Kit Grose wrote:

Just a note:
Your function doesn't currently use the RegExp function for anything
useful (you might as well use indexOf). RegExp is the right way to do
it, though, so you can enforce word boundaries to match complete
classNames only (if I want all a.pop to be new window links, I wouldn't
want a.popcorn to turn into a popup window).

See http://snook.ca/archives/javascript/your_favourite_1/ for more info
(specifically the update) on how to enforce word boundaries but allow
for multiple classnames.


good point - here it is modified to use word boundaries:


Word boundaries aren't right either; for exmple, they will match a hyphen, so matching on some-thing will match some-thing-else. As per the HTML spec, class names are space-separated, so you need to match on spaces and the beginning or end of the string.

To save time, Robert Nyman has already been through all these problems, so have a look at his "ultimate getElementsByClassName": <http://www.robertnyman.com/2005/11/07/the-ultimate- getelementsbyclassname/> including the comment from Bruce Weirdan explaining the above: <http://www.robertnyman.com/2005/11/07/the- ultimate-getelementsbyclassname/#comment-1583>

HTH,

Nick.
--
Nick Fitzsimons
http://www.nickfitz.co.uk/




*******************************************************************
List Guidelines: http://webstandardsgroup.org/mail/guidelines.cfm
Unsubscribe: http://webstandardsgroup.org/join/unsubscribe.cfm
Help: [EMAIL PROTECTED]
*******************************************************************

Reply via email to