Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #22465
| From | Joao Rodrigues <groups_jr-1@yahoo.com.br> |
|---|---|
| Newsgroups | comp.lang.javascript |
| Subject | Re: Regular expression error in hasClass()? |
| Date | 2013-12-28 23:43 -0200 |
| Organization | Aioe.org NNTP Server |
| Message-ID | <l9nune$9kc$1@speranza.aioe.org> (permalink) |
| References | <lsmdnVyNOOxSwSLPnZ2dnUVZ5j-dnZ2d@giganews.com> <beoub9d5qv59mq0571grds7ifo031cvfup@hive.bjoern.hoehrmann.de> <mtydnWvCfJ9S9yLPnZ2dnUVZ5tOdnZ2d@giganews.com> |
On 28/12/2013 22:20, Robert Crandal wrote:
> "Bjoern Hoehrmann" wrote:
>>
>> This does not access the class names for an element. It has to be
>>
>> if (re.test(e[j].className)) r.push(e[j])
>>
>> There are probably other errors, for instance, `\s` matches characters
>> that do not separate class names, and `name` might contain characters
>> that have a special meaning in regular expressions like `.` that need
>> to be escaped.
>>
>
> That was it! I thought it might be missing "className" somewhere in
> the hasClass() function.
>
> I found another error in this book later in Chapter 9 where he tries
> to call an undefined function named "byClass()". I think the author was
> refering to the previously defined "hasClass()" function.
>
> Oh, in the "Acknowledgements" section of this book, it also says:
>
> "I'd also like to thank my technical editor, Dan Webb, for thoroughly
> checking my code and reminding me of the finer points of the
> JavaScript language."
>
> I guess his thoroughness wasn't good enough, haha.
>
Is John Resig the author of JS Pro Techniques? If so, you might dismiss
the book.
A better written code by David Mark, author of "My Library":
<http://www.cinsoft.net/mylib.html>
function hasClassName (el, className) {
return (new RegExp('(^|\\s)' + className +
'(\\s|$)')).test(el.className);
}
--
Joao Rodrigues
Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Regular expression error in hasClass()? "Robert Crandal" <noreply2me@yahoo.com> - 2013-12-28 16:20 -0700
Re: Regular expression error in hasClass()? Bjoern Hoehrmann <bjoern@hoehrmann.de> - 2013-12-29 00:49 +0100
Re: Regular expression error in hasClass()? "Robert Crandal" <noreply2me@yahoo.com> - 2013-12-28 17:20 -0700
Re: Regular expression error in hasClass()? Joao Rodrigues <groups_jr-1@yahoo.com.br> - 2013-12-28 23:43 -0200
Re: Regular expression error in hasClass()? "Robert Crandal" <noreply2me@yahoo.com> - 2013-12-28 19:44 -0700
Re: Regular expression error in hasClass()? Hans-Georg Michna <hans-georgNoEmailPlease@michna.com> - 2013-12-29 12:16 +0100
Re: Regular expression error in hasClass()? Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-12-29 17:45 +0100
Re: Regular expression error in hasClass()? "Robert Crandal" <noreply2me@yahoo.com> - 2013-12-29 14:29 -0700
Re: Regular expression error in hasClass()? Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-12-30 10:33 +0100
Re: Regular expression error in hasClass()? williamc <temp4@williamc.com> - 2013-12-31 10:43 -0500
csiph-web