From: Garrett Smith on 5 Apr 2010 16:41 David Mark wrote: > Garrett Smith wrote: >> Hans-Georg Michna wrote: >>> On Sat, 03 Apr 2010 18:40:12 -0400, David Mark wrote: >>> >>>> there can only be one class attribute per element >>> But you shouldn't need to be reminded that, unlike the id >>> attribute, the class attribute takes multiple >>> white-space-separated identifiers. CSS uses each of them, and >>> JavaScript code can, of course, do that just as well. >>> >> In the html `class` attribute[1], multiple class names must be separated >> by white space characters[2]. From section 9.1 White space: >> >> | ... In HTML, only the following characters are defined as white space >> | characters: >> | >> | * ASCII space ( ) >> | * ASCII tab (	) >> | * ASCII form feed () >> | * Zero-width space (​) >> | >> | Line breaks are also white space characters.... >> >> Using zero-width space is going to make the code hard to read, and form >> feed is uncommon. >> >> A class match function that not excludes any of these characters risks >> failure. AIUI, a carriage return "\r", or "\u000d" should be a valid >> separator for two class tokens. Testing that hypothesis on the jQuery >> javascript library: >> >> var x = document.createElement("div"); >> x.innerHTML = "<span class='foo\rbar baz'>hey</span>"; >> jQuery(x.firstChild).hasClass("foo"); >> >> Result: false. > > Isn't this post s microcosm of your futility? You're using big words like a dork, trying to insult me but there is no wit. You missed the point. That point is to explain what "white space" means in HTML and the implications that it has on both className and, furthermore, the limitations in jQuery. You regurgitate specs and > then fall flat on your face trying to solve a simple problem. No, I tested a jQuery function against to see if it would produce the result that can be expected. What can be expected? Well, unless you read the spec, such assertions are based on worthless subjectivity. The HTML specification defines what can be expected, so that is what is posted. That test > is ludicrous for a number of reasons. For one, you aren't setting out > to test createElement or (for God's sake) innerHTML. It looks just like > jQuery's ill-conceived "feature tests". > Looks like a jQuery feature test? > And you didn't state which browser you tested in either. Perhaps it is > one of the ones jQuery doesn't "care" about. :) > I tested in Firefox 3.6. I would expect a similar result in other browsers. IE7: javascript:var x = document.createElement("div"); void(x.innerHTML = "<span class='foo\rbar baz'>hey</span>"); alert(jQuery(x.firstChild).hasClass("foo")); "false" >> Although I would generally not use \r as a separator for class, I would >> not expect the result produced. >> > > Neither would I. Testing with My Library[1]:- > Any, library, hopefully, would not result `false`. The expected result should be `true`. -- Garrett comp.lang.javascript FAQ: http://jibbering.com/faq/
From: David Mark on 5 Apr 2010 16:55 Garrett Smith wrote: > David Mark wrote: >> Garrett Smith wrote: >>> Hans-Georg Michna wrote: >>>> On Sat, 03 Apr 2010 18:40:12 -0400, David Mark wrote: >>>> >>>>> there can only be one class attribute per element >>>> But you shouldn't need to be reminded that, unlike the id >>>> attribute, the class attribute takes multiple >>>> white-space-separated identifiers. CSS uses each of them, and >>>> JavaScript code can, of course, do that just as well. >>>> >>> In the html `class` attribute[1], multiple class names must be separated >>> by white space characters[2]. From section 9.1 White space: >>> >>> | ... In HTML, only the following characters are defined as white space >>> | characters: >>> | >>> | * ASCII space ( ) >>> | * ASCII tab (	) >>> | * ASCII form feed () >>> | * Zero-width space (​) >>> | >>> | Line breaks are also white space characters.... >>> >>> Using zero-width space is going to make the code hard to read, and form >>> feed is uncommon. >>> >>> A class match function that not excludes any of these characters risks >>> failure. AIUI, a carriage return "\r", or "\u000d" should be a valid >>> separator for two class tokens. Testing that hypothesis on the jQuery >>> javascript library: >>> >>> var x = document.createElement("div"); >>> x.innerHTML = "<span class='foo\rbar baz'>hey</span>"; >>> jQuery(x.firstChild).hasClass("foo"); >>> >>> Result: false. >> >> Isn't this post s microcosm of your futility? > > You're using big words like a dork, trying to insult me but there is no > wit. You missed the point. LOL. You come off like a petulant school-child. > > That point is to explain what "white space" means in HTML and the > implications that it has on both className and, furthermore, the > limitations in jQuery. My point is that you are a pretty lousy teacher. > > You regurgitate specs and >> then fall flat on your face trying to solve a simple problem. > > No, I tested a jQuery function against to see if it would produce the > result that can be expected. What can be expected? Well, unless you read > the spec, such assertions are based on worthless subjectivity. > > The HTML specification defines what can be expected, so that is what is > posted. > > That test >> is ludicrous for a number of reasons. For one, you aren't setting out >> to test createElement or (for God's sake) innerHTML. It looks just like >> jQuery's ill-conceived "feature tests". >> > > Looks like a jQuery feature test? Yep. Just like one. > >> And you didn't state which browser you tested in either. Perhaps it is >> one of the ones jQuery doesn't "care" about. :) >> > > I tested in Firefox 3.6. I would expect a similar result in other browsers. > > IE7: > javascript:var x = document.createElement("div"); void(x.innerHTML = > "<span class='foo\rbar baz'>hey</span>"); > alert(jQuery(x.firstChild).hasClass("foo")); > > "false" > >>> Although I would generally not use \r as a separator for class, I would >>> not expect the result produced. >>> >> >> Neither would I. Testing with My Library[1]:- >> > Any, library, hopefully, would not result `false`. The expected result > should be `true`. Yep.
From: Garrett Smith on 5 Apr 2010 17:00 Hans-Georg Michna wrote: > On Sun, 04 Apr 2010 22:48:19 -0700, Garrett Smith wrote: > >> In the html `class` attribute[1], multiple class names must be separated >> by white space characters[2]. From section 9.1 White space: >> >> | ... In HTML, only the following characters are defined as white space >> | characters: >> | >> | * ASCII space ( ) >> | * ASCII tab (	) >> | * ASCII form feed () >> | * Zero-width space (​) >> | >> | Line breaks are also white space characters.... > > Thanks for the reminder. > > In http://winhlp.com/wxnet.htm , which underwent a radical > jqueryectomy last night (and survived in best shape), I now use, > for example, the expression: > > /\bcollapsed\b/.test(p.className) > Oh, that's no good. \b matches "-". javascript: alert( /\bcollapsed\b/.test("collapsed-dead") ) [...] > Removal and addition is another matter, but can also be done > with relatively simple regular expressions, so there is no > urgent need for extra code. For example, to remove: > > p.className = p.className. > replace(/(^|\s+)collapsed($|\s+)/g, " "); > > I'm not sure whether \s+ catches the more exotic white-space > stuff, but it probably does. See: http://perfectionkills.com/whitespace-deviations/ [...] > > Hm, how can any programmer worth his salt possibly bungle this > up? I believe all functions in JavaScript that recognize > white-space, like the regexp expressions \b and \s, recognize \r > as white-space. You'd have to go out of your way to put such a > defect in there. Does jQuery, like Microsoft, now also suffer > from the kid-programmers syndrome, the over-exuberant, but > inexperienced school-leavers? Here's the jQuery-free code, which > is not even significantly longer: They may have used a subset deliberately. I see: | var rclass = /[\n\t]/g, I don't know why they would choose that, but that's what they use. > > var x = document.createElement("div"); > x.innerHTML = "<span class='foo\rbar baz'>hey</span>"; > /\bfoo\b/.test(x.firstChild.className); > > Result: true, as expected. > Yes, but - /\bfoo\b/.test("foo-bar") - is also true. -- Garrett comp.lang.javascript FAQ: http://jibbering.com/faq/
From: Jorge on 5 Apr 2010 17:31 On Apr 5, 10:41 pm, Garrett Smith <dhtmlkitc...(a)gmail.com> wrote: Garrett, can you learn to quote correctly, please ? i.e, NOT like this: > You regurgitate specs and > > > then fall flat on your face trying to solve a simple problem. > That test > > > is ludicrous for a number of reasons. For one, you aren't setting out > > to test createElement or (for God's sake) innerHTML. It looks just like > > jQuery's ill-conceived "feature tests". Thanks, -- Jorge.
From: Hans-Georg Michna on 6 Apr 2010 18:25
On Mon, 05 Apr 2010 14:00:06 -0700, Garrett Smith wrote: >Hans-Georg Michna wrote: >> /\bcollapsed\b/.test(p.className) >Oh, that's no good. \b matches "-". Dammit! Have to rewrite, and it's getting a little longer. In the actual case it worked just fine, because there are no minus signs in the class attribute values. But that's no solution. So what would be the best way? Perhaps: /(^|\s)collapsed(\s|$)/.test(p.className) Seems a little more awkward, but what can we do? Hans-Georg |