Home > Web Front-end > JS Tutorial > JavaScript implements dynamically created CSS style rule scheme_javascript skills

JavaScript implements dynamically created CSS style rule scheme_javascript skills

WBOY
Release: 2016-05-16 16:36:56
Original
1525 people have browsed it

There are a lot of JavaScript codes in web applications now, and we are always looking for various solutions to make them faster.

1. We use event delegation to make event monitoring more efficient,
2. We use function debouncing technology to limit the number of times a given method is called within a period of time. Please refer to: How to prevent high-frequency triggering of event functions (Chinese translation)
3. We use JavaScript loader to load the resources we really need, etc.

There is another way to make our pages faster and more efficient. That is to dynamically add and delete certain styles in the style sheet directly through JS, instead of constantly querying DOM elements and applying various style. Here's how it works.

Get style sheet

You can choose any style sheet to add style rules. If you have a certain style sheet, you can add the ID attribute to the or