单击css内容属性 [英] Clicking on css content property

查看:165
本文介绍了单击css内容属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下代码在标头标记之前添加了一个图片。
如果在标题被点击之前添加图片时,如何添加javascript或jquery代码来处理某些任务。

The Following code adds an image before header tag. How can add javascript or jquery code for handling some task when the image added before the header was clicked.

h1::before 
{
    content: url(smiley.gif);
}

Html代码是:

 <html>
   <body>
     <h1>Hi </h1>
   </body>
 </html>


推荐答案

不是DOM的一部分,您只能将事件附加到原始元素或父项。

You cannot attach events on pseudo class elements since they are not part of the DOM, you can only attach events to the original elements or parents.

您可以创建包含图像的元素,并将其放置在与伪元素定位它,并将任何事件处理程序附加到它。

You can create an element containing the image and position it in the same place that the pseudo element is positioning it, and attach any event handler to it.

这篇关于单击css内容属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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