And if so, how do you select on with jQuery? I.e., $(\"#a b\")
looks for all nodes within the node with
id=a
.
Short answer is no. Letters, numbers, underscores, hyphens, periods and colons only.
(darn, karim beat me to it.)
While this is an old question I thought I would share info on the HTML 5 Spec for those who come across this question as I did a few years after it was asked.
According to the HTML 5 Spec:
The value must be unique amongst all the IDs in the element's home subtree and must contain at least one character. The value must not contain any space characters.
It also says:
There are no other restrictions on what form an ID can take; in particular, IDs can consist of just digits, start with a digit, start with an underscore, consist of just punctuation, etc.
This is an argument by analogy.
Consider the CLASS selector. Not the same as ID, but there are simlarities.
You obviously can't have a class name with an embedded space because a list of classes
<p class='a b c'>some text</p>
could not be distinguished from a single name with spaces.
Ok, you can't have a list of id names, anyway, so the analogy falls apart, but I think we've become too quick to try to insert spaces where they don't belong.
According to the HTML 4.0 specification for basic types:
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 (".").
And even if spaces were valid, an id attribute with spaces would be interpreted by jQuery as an ancestor descendant selector with the current selector syntax.