Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 680
Peter C Avatar asked Oct 12 '22 08:10

Peter C


1 Answers

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

like image 130
Alex Avatar answered Oct 19 '22 10:10

Alex