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

前端 未结 4 1070
醉话见心
醉话见心 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:24

    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

    some text

    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.

提交回复
热议问题