parseInt() and CSS naming was Re: [thelist] javascript "won't" subtract

Keith Dahlby dahlbyk at softhome.net
Sun Mar 9 16:35:01 CST 2003


For XHTML, the id attribute is of XML attribute type ID (see
http://www.w3.org/TR/REC-xml#sec-attribute-types).  This type must match
the Name production (http://www.w3.org/TR/REC-xml#dt-name):
A Name is a token beginning with a letter or one of a few punctuation
characters, and continuing with letters, digits, hyphens, underscores,
colons, or full stops, together known as name characters.

 From the HTML 4.01 spec (http://www.w3.org/TR/html401/types.html#h-6.2):
ID and NAME tokens must begin with a letter ([A-Za-z]) and may be followed
by any number of letters, digits ([0-9]), hyphens ("-"), underscores ("_"),
colons (":"), and periods (".").

The only constraint that I can find on selectors in CSS is how patterns are
matched (http://www.w3.org/TR/REC-CSS2/selector.html#type-selectors).  This
restricts the use of colons and periods.  And though I've heard people talk
about it before, I've never seen anything that indicates that hyphens are
prohibited (and a quick check shows that pages using them validate).  HTH.

Cheers ~ K

At 02:29 PM 3/9/2003, you wrote:
>On Sat, Mar 08, 2003 at 04:45:46PM -0600, Erik Mattheis wrote:
> > JavaScript isn't a typed language, so it will treat a number as a
> > number when needed and as a string when needed - so no need to use
> > parseInt() (that's not the problem but it's unneeded.
>
>I've found in some forms that this /is/ actually needed. It's been ages
>since I first ran across the problem and I don't remember which browsers
>it was in but... when the data came in from the form javascript was
>treating it as as string containing a "number" instead of an actual number.
>As a result I've gotten into the habit of wrapping form numbers in parseInt().
>
> > Also, I believe the same naming convention of not starting with a digit
> > applies to the id and name attributes in HTML
>
>I remember that convention as well -- however, the page validates as XHTML
>1.0 transitional AND CSS-2 happy. I went back and looked through the specs
>and couldn't find anything on naming conventions. Does anyone know where
>the W3C hides that info? I breezed through ID in both CSS-1 and CSS-2, but
>I didn't see it. There's also the rule of no dashes in IDs and CLASSes,
>but again
>I couldn't find it in the actual spec.
>
>emma




More information about the thelist mailing list