Holla Tech - Learn

CSS Properties
 

Similar to the html() method, the css() method can be used to get and set CSS property values.
For example:
HTML: 

<p>Some text</p> 

 

CSS: 

p {
  background-color:red;
  color: white;

  

JS: 

$(function() {
  alert($(“p”).css(“background-color”));
  $(“p”).css(“background-color”, “blue”);
}); 

 

NOTE!
The code above alerts the background-color property of the paragraph and then sets it to blue.

Multiple Properties
 

To set multiple CSS properties, the css() method uses JSON syntax, which is:

css({“property”:“value”,“property”:“value”,…}); 

 

As you can see, the syntax consists of “property”:”value” pairs, which are comma separated and enclosed in curly brackets { }.
For Example:

$(“p”).css({“color”: “red”, “font-size”: “200%”}); 

 

This will set the color and font-size properties of the paragraph.

NOTE!
You can specify any number of properties using this JSON syntax.

BACK NEXT

CLICK ON THE BUTTON BELOW TO GO TO THE jQUERY MAIN COURSE PAGE. 

jQUERY MAIN COURSE PAGE

 


© License: All Rights Reserved 


CONTACT HOLLA TECH – LEARN SUPPORT