There's a similar discussion here : CSS data attribute new line character & pseudo-element content value
Problem is, this didn't work if the attr is set via Javascript
I understand that \A
doesn't work in attr, but now 

doesn't work on attr via Javascript, is there any way to get this working?
const ele = document.getElementById('my-ele')
ele.classList.add('loading');
ele.setAttribute('loading-text', 'Your file is being generated...
This may take some minutes');
.loading::after {
content: attr(loading-text);
}
<div id="my-ele"></div>
You can't select pseudo elements in jQuery because they are not part of DOM. But you can add a specific class to the parent element and control its pseudo elements in CSS. Show activity on this post. We can also rely on custom properties (aka CSS variables) in order to manipulate pseudo-element.
The attr() CSS function is used to retrieve the value of an attribute of the selected element and use it in the stylesheet. It can also be used on pseudo-elements, in which case the value of the attribute on the pseudo-element's originating element is returned.
Special welcome offer: get $100 of free credit. CSS ::before and ::after pseudo-elements allow you to insert “content” before and after any non-replaced element (e.g. they work on a <div> but not an <input> ). This effectively allows you to show something on a web page that might not be present in the HTML content.
Use a plain newline character (\n
in your JavaScript string), fix the getElementById()
call (get rid of "#"), and add white-space: pre-wrap;
to the CSS.
const ele = document.getElementById('my-ele')
ele.classList.add('loading');
ele.setAttribute('loading-text', 'Your file is being generated...\nThis may take some minutes');
.loading::after {
white-space: pre-wrap;
content: attr(loading-text);
}
<div id="my-ele"></div>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With