1

I made this function to "split" my elements and give them background-colors:

var colors = ['red','yellow','green','blue'];

function splitColors($item) {
    $item.each(function(i) {
        $(this).addClass(colors[i % 4]);
    });
}

splitColors($('.comment:before'));

now I want to apply this function on a before element in my DOM, but it doesn't work.

Can I access the ::before element in jQuery?

I can't use a real element, cause the WordPress comment section don't allow own markup..

Thanks!

Lukas Niestrat
  • 715
  • 1
  • 5
  • 16

1 Answers1

1

I think this works:

splitColors($('.comment').before());
Farzin Kanzi
  • 3,380
  • 2
  • 21
  • 23