Read and write css attributes of HTML elements

高洛峰
Release: 2016-11-24 09:46:26
Original
1320 people have browsed it

jQuery’s css() method is used to set or read the css attributes of HTML elements.

The CSS syntax for reading elements is as follows:

css("propertyname");

For example, the following code gets the background color of the first

element.

[javascript]

$("p").css("background-color");

$("p").css("background-color");

Use the following Syntax to set CSS properties of HTML elements:

css("propertyname", "value");

For example, the following code sets the background color to yellow for all

elements.

[html] 
  
  
  
      
    JQuery Demo  
      
      

This is a heading

This is a paragraph.

This is a paragraph.

This is a paragraph.

This is a paragraph.

JQuery Demo

This is a heading

This is a paragraph.

This is a paragraph.

This is a paragraph.

This is a paragraph.

www.2cto.com
Copy after login

Read and write css attributes of HTML elements

css() also supports multiple CSS properties at the same time: its syntax is as follows:

css({"propertyname":"value","propertyname":"value",…});

For example:

[javascript] view plaincopyprint?

$("p").css({"background-color":"yellow","font-size":"200%"});

$(" p").css({"background-color":"yellow","font-size":"200%"});


Related labels:
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
Popular Tutorials
More>
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!