how to select :after element using jquery

前端 未结 4 1160
名媛妹妹
名媛妹妹 2020-12-16 15:25

Bellow is my codes.what i have tried.when this popup appear i want to use this close button to close entire popbox.

CSS code

.bigdiv{
    display:non         


        
4条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-16 16:01

    Unfortunately, you can't select pseudo-elements in jQuery (or JavaScript in general).

    jQuery's appendTo() method works exactly like CSS :after though, so it might work as a replacement (albeit not so elegant as pure CSS solution).

    e.g instead of:

    .bigdiv:after {
        cursor:pointer;
        content:url('http://static.doers.lk/img/closebox.png');
        position: relative;
        right: -195px;
        top: -310px;
        z-index: 999;
    }
    

    Try it like this

    CSS:

    .bigdivAfter {
        cursor:pointer;
        position: relative;
        right: -195px;
        top: -310px;
        z-index: 999;
    }
    

    JS:

    $("
    ").appendTo(".bigdiv");

    And then you can select the closebox image as normal.

提交回复
热议问题