W3Schools.com

jQuery CSS Manipulation


jQuery css() Method

jQuery has one important method for CSS manipulation: css()

The css() method has three different syntaxes, to perform different tasks.

  • css(name) - Return CSS property value
  • css(name,value) - Set CSS property and value
  • css({properties}) - Set multiple CSS properties and values

Return CSS Property

Use css(name) to return the specified CSS property value of the FIRST matched element:

Example

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

Try it yourself »


Set CSS Property and Value

Use css(name,value) to set the specified CSS property for ALL matched elements:

Example

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

Try it yourself »


Set Multiple CSS Property/Value Pairs

Use css({properties}) to set one or more CSS property/value pairs for the selected elements:

Example

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

Try it yourself »


jQuery height() and width() Methods

jQuery has two important methods for size manipulation.

  • height()
  • width()

Size Manipulation Examples

The height() method sets the height of all matching elements:

Example

$("#div1").height("200px");

Try it yourself »

The width() method sets the width of all matching elements:

Example

$("#div2").width("300px");

Try it yourself »


jQuery CSS Methods From this Page:

CSS Properties Description
$(selector).css(name) Get the style property value of the first matched element
$(selector).css(name,value) Set the value of one style property for matched elements
$(selector).css({properties}) Set multiple style properties for matched elements
$(selector).height(value) Set the height of matched elements
$(selector).width(value) Set the width of matched elements

For a full jQuery CSS reference, please go to our jQuery CSS Methods Reference.




W3Schools Certification

W3Schools' Online Certification

The perfect solution for professionals who need to balance work, family, and career building.

More than 10 000 certificates already issued!

Get Your Certificate »

The HTML Certificate documents your knowledge of HTML.

The CSS Certificate documents your knowledge of advanced CSS.

The JavaScript Certificate documents your knowledge of JavaScript and HTML DOM.

The jQuery Certificate documents your knowledge of jQuery.

The XML Certificate documents your knowledge of XML, XML DOM and XSLT.

The ASP Certificate documents your knowledge of ASP, SQL, and ADO.

The PHP Certificate documents your knowledge of PHP and SQL (MySQL).

WEB HOSTING
Best Web Hosting
PHP MySQL Hosting
Best Hosting Coupons
UK Reseller Hosting
Cloud Hosting
Top Web Hosting
$3.98 Unlimited Hosting
Premium Website Design
WEB BUILDING
Download XML Editor
FREE Website BUILDER
Best Website Templates Top CSS Templates
CREATE HTML Websites
EASY WEBSITE BUILDER
W3SCHOOLS EXAMS
Get Certified in:
HTML, CSS, JavaScript, XML, PHP, and ASP
W3SCHOOLS BOOKS
New Books:
HTML, CSS
JavaScript, and Ajax
STATISTICS
Browser Statistics
Browser OS
Browser Display
SHARE THIS PAGE