在 CSS3 上使用 JQuery 触发事件:伪元素之后?
我有这个 CSS
#popup .title:hover:after {
content: "hide";
position: absolute;
top: 3px;
right: -32px;
background: orange;
padding: 2px 4px;
font-size: 10px;
border-radius: 4px;
}
并想在其上使用点击事件 .remove()
但是:$('#popup .title:hover:after').length
在文档上返回 0准备好了..
有办法做到这一点吗?
I have this CSS
#popup .title:hover:after {
content: "hide";
position: absolute;
top: 3px;
right: -32px;
background: orange;
padding: 2px 4px;
font-size: 10px;
border-radius: 4px;
}
and wanted to use a click event on it to .remove()
the <div id="#popup">
But:
$('#popup .title:hover:after').length
returns 0 on document ready..
Is there a way to do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
抱歉,没有。使用
:after
(或:before
,或 CSS 3 等效项::after
和::before) 不是 DOM 的一部分,因此无法选择。
来自 CSS 2.1 规范:
Sorry, no. Pseudo-elements created with
:after
(or:before
, or the CSS 3 equivalents::after
and::before
) are not part of the DOM and therefore cannot be selected.From the CSS 2.1 spec:
遗憾的是,伪元素不在 dom 中。所以你的浏览器将无法看到它们:(
因为你希望它们在页面加载后加载或者已经读取了CSS,所以我会使用after:使用javascript来完成它
,现在已经添加了我可以玩用 javascript 和删除等等。
Sadly Pseduo elements aren't in the dom. So your browser won't be able to see them :(
As you want them to load in after the page has loaded or would have read the css i would do it with javascript using the after:
and now that has been added i can play with it with javascript and remove etc etc.