Modify css style for pseudo element :after content with Jquery

前端 未结 3 945
情深已故
情深已故 2020-12-07 20:51

I have baloon shape designed with CSS3.
JS Fiddle Example It\'s have triangle made with

:after {
    content: \"\";
}

I need to moving

3条回答
  •  庸人自扰
    2020-12-07 21:24

    There is a much easier way: just set the pseudo element's content property value to attr(some-attribute-name), it will use the value of the HTML attribute on the parent as the content for the pseudo element. You can then use the setAttribute() method on the parent element to change the value dynamically. Below are mock snippets of how this method would look in action. I also did a blog post with further details that contains a live example fiddle.

    CSS

    #SomeElement:after {
        content: attr(some-attribute-name);
    }
    

    HTML

    JavaScript (to change pseudo content)

    var someElement = document.getElementById('SomeElement');
    someElement.setAttribute('some-attribute-name', 'New pseudo content here!');
    

提交回复
热议问题