And if so, how do you select on with jQuery? I.e., $("#a b")
looks for all <b>
nodes within the node with id=a
.
views:
155answers:
3According 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.
Short answer is no. Letters, numbers, underscores, hyphens, periods and colons only.
(darn, karim beat me to it.)
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.