Possible to make a:after/before pseudo elements clickable as part of the link?

后端 未结 8 1762
不知归路
不知归路 2020-12-16 09:42

pseudo elements a:after a:before allow you to add text that appears to be part of the link. However, I can\'t seem to figure out a way to make that portion clickable as part

8条回答
  •  北荒
    北荒 (楼主)
    2020-12-16 10:04

    I wrapped the link and the text separately -- the :before goes on the container and the link goes inside. This way I can use the :before as a jQuery tigger and the text as a link. HTML:

  • My Link Text
  • CSS:

    li.before-here:before{ //some css like an image }
    

    Jquery:

    $("li.before-here").click(function(){ //do something});
    

    I'm using this to create a hide/show toggle in a tree -- this gives me the button I need on the left and allows me to link to the parent.

提交回复
热议问题