0

I'm trying to change width and height of pseudo-class element through the attribute. I'm doing this because I cannot change pseudo element in javascript. What's wrong in my code? Mozilla says its posible: https://developer.mozilla.org/en/docs/Web/CSS/attr#Examples

.loader::before {
height: 30px;
width: attr(data-width);
display: block;
position: absolute;
background-color: red;
content: '';}

javascript:

$('.loader').attr('data-width', '100px');});

https://jsfiddle.net/9j2pbbzd/

User_111
  • 49
  • 7

2 Answers2

0

Be careful, at the moment you can use attr() just into content property. Look at this similar answer https://stackoverflow.com/a/27529435/1849721

0

What if you create a class with the width/height you want the pseudo element to have and use JS to add/remove this classes as you want to ?

André C. Rocha
  • 301
  • 5
  • 17