问题
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?
回答1:
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
来源:https://stackoverflow.com/questions/5598675/javascript-find-pseudo-elements