In HTML5, CSS selectors seem to work well with data- * attributes. For instance:
<style>
div[data-foo='bar'] {
background:#eee;
}
</style>
<div data-foo='bar'>colored</div>
<div>not colored</div>
will stylize the first correctly. But attempts to select such elements using api selectors fail. Examples:
var foos = document.querySelectorAll("div[data-foo]='bar'");
or
var foos = document.querySelectorAll("div data-foo='bar'");
in Chrome and Safari, this causes a cryptic error:
SYNTAX_ERR: DOM 12 exception
Any thoughts on how to use selectors-api to correctly select elements based on data- * attributes?
source
share