jQuery and pseudo-elements

前端 未结 2 1231
无人共我
无人共我 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:29

    You can't. Content created by :after or :before is not part of the DOM and therefore cannot be selected or modified.

    If you have a look at this example fiddle and inspect the DOM in Firebug or similar you will see that the pseudo-element is not present in the DOM tree.

    A potential solution would be to apply a class to the element you want to change, and to style that class appropriately in CSS:

    $("div").addClass("newClass");
    

    See this fiddle for an example.

提交回复
热议问题