Can a DOM element have an ID that contains a space?

前端 未结 4 1073
醉话见心
醉话见心 2020-12-06 04:36

And if so, how do you select on with jQuery? I.e., $(\"#a b\") looks for all nodes within the node with id=a.

4条回答
  •  不知归路
    2020-12-06 05:27

    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.

提交回复
热议问题