jquery modifies CSS pseudo-element properties method _jquery

Source: Internet
Author: User

CSS pseudo elements (pseudo elements) are not DOM elements, so you cannot select them directly.

Suppose you have the following HTML code:

<div class= "Techbrood" id= "Td_pseudo" >techbrood introduction</div>

and CSS code:

. techbrood:before {
width:0
}

Now you want to dynamically set the Techbrood:before width property to 100% in the click event of an element.

There are two methods, one is to add a new style:

$ (' head '). Append ("<style>.techbrood::before{width:100%}</style>");

(Note that this method will affect all elements of class Techbrood)

Another method is to add a new class to the element and to change the properties of the pseudo element by setting the properties of the new class:

. techbrood.change:before{
width:100%;
}

jquery Code:

$ (' #td_pseudo '). addclass ("Change");
Related Article

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.