How to use JavaScript to obtain Pseudo-Element attributes _ javascript skills

Source: Internet
Author: User
This article describes how to use JavaScript to obtain the attributes of a Pseudo-Element. This article provides the implementation code. For more information, see pseudo-elements in CSS) very useful-you can use it to create CSS triangles and use them in the prompt box. you can also use it to complete many simple tasks without the need for additional HTML elements. Previously, the CSS attributes of pseudo elements could not be obtained using JavaScript, but now, a new JavaScript method can be used to access them! Suppose your CSS code is like this:

The code is as follows:


. Element: before {
Content: 'New ';
Color: rgb (255, 0, 0 );
}


To obtain the style attributes in. element: before, you can use the following JavaScript code:

The code is as follows:


Var color = window. getComputedStyle (
Document. querySelector ('. element'),': before'
). GetPropertyValue ('color ')


Use the pseudo element as the second parameter of the window. getComputedStyle method. you can obtain the attributes in the pseudo element style! Put this technique into your knowledge base. with the development of browsers, pseudo elements will become more and more useful!
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.