How to set the css of div in js

藏色散人
Release: 2023-01-05 16:12:46
Original
4272 people have browsed it

JS method to set the css of div: first introduce the Jquery plug-in; then change the style of html by using jquery's css method, or use jquery's addClass method to change or add a css style to html.

How to set the css of div in js

The operating environment of this article: windows7 system, jquery version 1.8.3, Dell G3 computer.

In order to be more convenient and easier to use, we introduce the Jquery plug-in and use Jquery to operate.

How to set the css of div in js

Our html is very simple, just a div with a paragraph of text inside.

How to set the css of div in js

Open the page, now the div does not use css style,

How to set the css of div in js

To change the style of html, we can use it directly jquery css method:

$("#div_d").css("background-color","#0e90d2");
Copy after login

How to set the css of div in js

Refresh the page and you can see that the background color of the div has now turned blue.

How to set the css of div in js

When multiple css style values need to be modified, directly changing the css is troublesome and requires multiple calls. At this time, our more reasonable method is to change or add a css style to html.

Use jquery's addClass method: $("#div_d").addClass("div_class");

How to set the css of div in js

##Our css style div_class is defined as shown in the figure , multiple style values are defined.

How to set the css of div in js

Look at the effect of the current page again, the style has been added successfully. [Recommended learning:

javascript advanced tutorial]

How to set the css of div in js

The above is the detailed content of How to set the css of div in js. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
js
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!