Javascript find pseudo elements

♀尐吖头ヾ 提交于 2019-12-23 10:08:31

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!