0

I'm trying to get a colour from a data-attribute (that can be different per page) and pass that colour into a ::before/::after with jQuery. Currently have this:

var colour = $('.subtitle.fancy').attr('data-attribute');
  $('.blog-footer .subtitle.fancy span').after(function(){
    $(this).css('border-bottom', '2px solid #' + colour);
});

Obviously not working - is there a way to make this work?

Alex Murray
  • 265
  • 6
  • 21
  • 1
    `:before` and `:after` are not part of the DOM... And therefore, cannot be modified via JS. And the [`.after`](http://api.jquery.com/after/) method you are using is to insert elements after another... – Louys Patrice Bessette Mar 29 '17 at 21:02
  • You cannot target the psuedo element :after with jQuery/javascript, but [this question](http://stackoverflow.com/questions/17788990/access-the-css-after-selector-with-jquery) shows you how you can potentially get the desired affect. – Joe Lissner Mar 29 '17 at 21:06

0 Answers0