Modifying the style of the Before,after pseudo-class using the Javascript,jquery implementation

Source: Internet
Author: User

Classes such as the following HTML and style
<p class= "Red" >hello,are you kain?</p>

CSS Styles

. red:before {    ' red ',    background-color  : Red}

1. Use JavaScript or jquery to switch, add the class of the element

. green:before {    ' green ';    Background-color:green;} $ (' P '). addclass (' green ');

2. Insert a style dynamically in the existing style document

Document.stylesheet[0].addrule ('. Red:before ', ' Background-color:green ');d ocument.stylesheet[0]. Insertrule ('. Red:before{background-color:green} ', 0);

3. Create a new style sheet and insert it into it using JavaScript or Jquert

var style = document.createlement (' style '= style.sheet;sheet.addrule ('. Red:before ', ' Background-color:green '); Sheet.insertrule ('. Red:before{background-color:green} ', 0); // jQuery$ (' <style>.red:before{background-color:green}</style> '). AppendTo (' head ');

4. Using the HTML5 data-property, use attr () dynamic modification in the attribute.

Add the Data-attr= "red" attribute to the P tag and then $ (' red '). attr (' data-attr ', ' green ');

Modifying the style of the Before,after pseudo-class (go) using the Javascript,jquery implementation

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.