Is there a way to use jQuery to set the CSS counter-increment attribute on ".demo:before
" even though jQuery cannot access pseudo elements directly? I recall seeing a suggestion on Stack Overflow about using a data attribute and then referencing that value in the CSS, but it doesn't seem to be working for me. Can this actually be achieved?
Here's a simplified example to illustrate my question: http://jsfiddle.net/4h7hk8td/
HTML:
<ul class="demo">
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
</ul>
JS:
// 1) The user defines the unit size
var myUnit = 100;
// 2) Saving the unit size as a data attribute
$('.demo li').attr('data-unit', myUnit);
CSS:
.demo {
counter-reset: list;
}
.demo li:before {
/* 3) Attempting to get the data attribute with jQuery and use it as an increment - currently not functioning as intended :( */
counter-increment: list attr(data-unit);
content: counter(list);
}