Peter C
Peter C

Reputation: 6307

Javascript find pseudo elements

So I've been work on a CSS selector engine, and I want to support pseudo-elements (::before, ::after, ::selection, ::first-line, etc). I noticed Slick, Sizzle, and some other popular engines seem to support them, but when looking through their code I found no code for it (now granted, I didn't look that hard). Does anyone know how they do it or some way I could do it?

Upvotes: 5

Views: 4530

Answers (1)

Alex
Alex

Reputation: 344

Here's a simple way to find them in Webkit using jQuery, can fairly easily be converted to standard JS:

$('*').filter(function(){return getComputedStyle(this, ':before').length != 0});

For Gecko based browsers you need something a little different (haven't tested in IE). Hope this helps

Upvotes: 4

Related Questions