jQuery and pseudo-elements

前端 未结 2 1254
无人共我
无人共我 2020-11-27 21:52

I tried to dynamically change the position of an element which is defined in CSS with :after. Using this:

$(function(){
    $(\'div::after\').c         


        
2条回答
  •  青春惊慌失措
    2020-11-27 22:33

    add CSS:

    p.special:before {
        content: "bar";
        position: absolute;
        top : 10px;
    }
    

    assuming the style sheet where the code above was put is the first one on the page, use this to change it:

    document.styleSheets[0].addRule('p.special:before','top: 15px;');
    

提交回复
热议问题