jQuery Get And Set

jQuery get and set methods are used to get or set the style properties of the selected element.

jQuery css() Method

jQuery css() method is used to set or get(return) the style properties of the selected HTML element.

General Syntax Of Get A CSS Property Value

You can find the general properties of the selected elements through the given below syntax.

    
   $(selector).css("propertyName");   
   

Source Code

          
            $(document).ready(function () {
  $("h2,h3").click(function () {
    var color = $(this).css("color");
    $("#result").html(color);
  });
});          
        
Try it now

Set A single CSS Style Property & Value To The Element

To set a single CSS property and value to the element, pass a single CSS property name and value as separate parameters to the css() method.

Source Code

          
            $(selector).css("propertyName", "value");          
        
Try it now

Set multiple CSS Style Properties And Values

You can also pass more than one CSS property and value inside the CSS() method. Let us see its general syntax.

    
      $(selector).css({"propertyName":"value", "propertyName":"value", ...}); 
   

Source Code

          
            $(document).ready(function () {
  $(".btn-effect").click(function () {
    $("h2,h3").css({ "background-color": "green", color: "white", padding: "10px" });
  });
});          
        
Try it now

Web Tutorials

jQuery Get And Set
Html Tutorial HTML
Javascript Tutorial JAVASCRIPT
Css Tutorial CSS
Bootstrap 5 Tutorial BOOTSTRAP 5
Bootstrap 4 Tutorial BOOTSTRAP 4