在 CSS3 上使用 JQuery 触发事件:伪元素之后?

发布于 2024-12-28 21:38:30 字数 442 浏览 2 评论 0原文

我有这个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

站稳脚跟 2025-01-04 21:38:30

有办法吗?

抱歉,没有。使用 :after (或 :before,或 CSS 3 等效项 ::after::before) 不是 DOM 的一部分,因此无法选择。

来自 CSS 2.1 规范

生成的内容不会更改文档树。特别是,它
不会反馈到文档语言处理器(例如,对于
重新解析)。

Is there a way?

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:

Generated content does not alter the document tree. In particular, it
is not fed back to the document language processor (e.g., for
reparsing).

病毒体 2025-01-04 21:38:30

遗憾的是,伪元素不在 dom 中。所以你的浏览器将无法看到它们:(

因为你希望它们在页面加载后加载或者已经读取了CSS,所以我会使用after:使用javascript来完成它

 $('#popup .title').after(); (you'll need to ploop your code in still)

,现在已经添加了我可以玩用 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:

 $('#popup .title').after(); (you'll need to ploop your code in still)

and now that has been added i can play with it with javascript and remove etc etc.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文