Javascript查找伪元素 [英] Javascript find pseudo elements

查看:120
本文介绍了Javascript查找伪元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我一直在一个CSS选择器引擎上工作,我想支持伪元素(:: before,:: after,:: selection,:: first-line等)。我注意到Slick,Sizzle和一些其他流行的引擎似乎支持他们,但是当看看他们的代码,我发现没有代码(现在授予,我没有看起来那么难)。

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?

推荐答案

这里有一个简单的方法来找到他们在Webkit使用jQuery,可以很容易地转换为标准的JS:

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});

对于基于Gecko的浏览器,你需要一些不同的东西希望这有助于

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

这篇关于Javascript查找伪元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆