Some content gets generated by CSS and I need to get the "live" value.
The element in question has this CSS
::before {
counter-increment: num;
content: counter(num) ". ";
}
I tried
getComputedStyle(elem, '::before').getPropertyValue('content');
and it returns
counter(num) ". "
and not the "live" value I was expecting (hoping).
How can I get the actual text that is displayed?
On Friday, 16 July 2021 at 09:53:08 UTC+2, Andrew Poulos wrote:
Some content gets generated by CSS and I need to get the "live" value.
The element in question has this CSS
::before {
counter-increment: num;
content: counter(num) ". ";
}
I tried
getComputedStyle(elem, '::before').getPropertyValue('content');
and it returns
counter(num) ". "
and not the "live" value I was expecting (hoping).
How can I get the actual text that is displayed?
As far as I can tell, there is no way to access that value. Indeed, you cannot even select the generated text (I mean, not even with your mouse).
See also here: <https://stackoverflow.com/questions/532073/how-can-i-read-the-applied-css-counter-value>
The obvious work-around is to generate the numbering from JS, i.e. just do not use that CSS: or do, but then be prepared to compute the same on the scripting side some other way, and make also sure that who writes the CSS talks to who writes the JS andvice versa...
On 17/07/2021 12:43 am, Julio Di Egidio wrote:
On Friday, 16 July 2021 at 09:53:08 UTC+2, Andrew Poulos wrote:
Some content gets generated by CSS and I need to get the "live" value.
The element in question has this CSS
::before {
counter-increment: num;
content: counter(num) ". ";
}
I tried
getComputedStyle(elem, '::before').getPropertyValue('content');
and it returns
counter(num) ". "
and not the "live" value I was expecting (hoping).
How can I get the actual text that is displayed?
As far as I can tell, there is no way to access that value. Indeed,
you cannot even select the generated text (I mean, not even with your
mouse).
See also here:
<https://stackoverflow.com/questions/532073/how-can-i-read-the-applied-css-counter-value>
Thanks for link.
The obvious work-around is to generate the numbering from JS, i.e.
just do not use that CSS: or do, but then be prepared to compute the
same on the scripting side some other way, and make also sure that who
writes the CSS talks to who writes the JS and vice versa...
Funny that the browser knows what text to display but I will need to
script some workaround to get it.
On 17/07/2021 9:15 am, Andrew Poulos wrote:
On 17/07/2021 12:43 am, Julio Di Egidio wrote:
On Friday, 16 July 2021 at 09:53:08 UTC+2, Andrew Poulos wrote:
Some content gets generated by CSS and I need to get the "live" value. >>>
The element in question has this CSS
::before {
counter-increment: num;
content: counter(num) ". ";
}
I tried
getComputedStyle(elem, '::before').getPropertyValue('content');
and it returns
counter(num) ". "
and not the "live" value I was expecting (hoping).
How can I get the actual text that is displayed?
As far as I can tell, there is no way to access that value. Indeed,
you cannot even select the generated text (I mean, not even with your
mouse).
See also here:
<https://stackoverflow.com/questions/532073/how-can-i-read-the-applied-css-counter-value>
Thanks for link.
The obvious work-around is to generate the numbering from JS, i.e.
just do not use that CSS: or do, but then be prepared to compute the
same on the scripting side some other way, and make also sure that who
writes the CSS talks to who writes the JS and vice versa...
Funny that the browser knows what text to display but I will need to script some workaround to get it.
I guess it's something similar with the "numbers" for ordered list items
in that you can't query what a browser is actually displaying.
Some content gets generated by CSS and I need to get the "live" value.
The element in question has this CSS
::before {
counter-increment: num;
content: counter(num) ". ";
}
I tried
getComputedStyle(elem, '::before').getPropertyValue('content');
and it returns
counter(num) ". "
and not the "live" value I was expecting (hoping).
How can I get the actual text that is displayed?
On Friday, July 16, 2021 at 2:53:08 AM UTC-5, Andrew Poulos wrote:
Some content gets generated by CSS and I need to get the "live" value.
The element in question has this CSS
::before {
counter-increment: num;
content: counter(num) ". ";
}
I tried
getComputedStyle(elem, '::before').getPropertyValue('content');
and it returns
counter(num) ". "
and not the "live" value I was expecting (hoping).
How can I get the actual text that is displayed?
This is not possible currently. There are hacks that might work
but with the complexity involved it's probably better to do this with JavaScript.
There is a new CSS standard in the works `target-counter()` to make this possible in the future:
<https://github.com/w3c/csswg-drafts/issues/5879>
On Sunday, 18 July 2021 at 17:27:26 UTC+2, Michael Haufe (TNO) wrote:
This is not possible currently. There are hacks that might work
but with the complexity involved it's probably better to do this with JavaScript.
There are no hacks, there is just no access from JS to the runtime value of those properties.
There is a new CSS standard in the works `target-counter()` to make this possible in the future:
<https://github.com/w3c/csswg-drafts/issues/5879>"The target-counter() function does exactly this in CSS, not JS", i.e. same as above.
On Saturday, 17 July 2021 at 03:36:36 UTC+2, Andrew Poulos wrote:<snip>
I guess it's something similar with the "numbers" for ordered list items
in that you can't query what a browser is actually displaying.
Right. I suppose it has to do with how the browser is structured,
On Tuesday, July 20, 2021 at 6:06:58 AM UTC-5, ju...@diegidio.name wrote:<snip>
On Sunday, 18 July 2021 at 17:27:26 UTC+2, Michael Haufe (TNO) wrote:
There is a new CSS standard in the works `target-counter()` to make this possible in the future:
<https://github.com/w3c/csswg-drafts/issues/5879>
"The target-counter() function does exactly this in CSS, not JS", i.e. same as above.
The difference being that this value could be accessible from the CSSOM,
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 349 |
Nodes: | 16 (2 / 14) |
Uptime: | 104:27:16 |
Calls: | 7,610 |
Calls today: | 1 |
Files: | 12,786 |
Messages: | 5,682,633 |