admin管理员组文章数量:1353114
Try to execute this 2 code blocks in error console:
First one. Outputs NodeList.
var selector = "*[data-type=day][data-day='23']";
var a = document.querySelectorAll( selector );
alert( a );
Second one. Generates error.
var selector = "*[data-type=day][data-day=23]";
var a = document.querySelectorAll( selector );
alert( a );
Why data-type=day
is ok syntax and data-day=23
is not? Should attribute values always be wrapped as data-type='day'
?
Here is the exception, which raises in second case:
[Exception... "An invalid or illegal string was specified" code: "12" nsresult: "0x8053000c (SyntaxError)" ]
Try to execute this 2 code blocks in error console:
First one. Outputs NodeList.
var selector = "*[data-type=day][data-day='23']";
var a = document.querySelectorAll( selector );
alert( a );
Second one. Generates error.
var selector = "*[data-type=day][data-day=23]";
var a = document.querySelectorAll( selector );
alert( a );
Why data-type=day
is ok syntax and data-day=23
is not? Should attribute values always be wrapped as data-type='day'
?
Here is the exception, which raises in second case:
Share Improve this question edited Oct 23, 2012 at 6:48 BoltClock 725k165 gold badges1.4k silver badges1.4k bronze badges asked Oct 23, 2012 at 6:44 bhovhannesbhovhannes 5,6872 gold badges28 silver badges37 bronze badges 0[Exception... "An invalid or illegal string was specified" code: "12" nsresult: "0x8053000c (SyntaxError)" ]
1 Answer
Reset to default 10The browser is just following the specification which says:
Attribute values must be CSS identifiers or strings.
and on identifiers:
In CSS, identifiers (including element names, classes, and IDs in selectors) can contain only the characters [a-zA-Z0-9] and ISO 10646 characters U+00A0 and higher, plus the hyphen (-) and the underscore (_); they cannot start with a digit…
So 23
(which starts with a digit) must expressed as a string:
Strings can either be written with double quotes or with single quotes
本文标签: javascriptquerySelectorAll invalid syntaxStack Overflow
版权声明:本文标题:javascript - querySelectorAll invalid syntax - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1743896977a2557968.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论