Loading Please Wait...

Logo Lynxsia IT Solutions

jQuery DOM CSS

JQ DOM CSS

With jQuery, it is easy to manipulate the style of elements.

jQuery Manipulating CSS

jQuery has several methods for CSS manipulation. We will look at the following methods:

  • addClass() - Adds one or more classes to the selected elements
  • removeClass() - Removes one or more classes from the selected elements
  • toggleClass() - Toggles between adding/removing classes from the selected elements
  • css() - Sets or returns the style attribute
jQuery addClass() Method

The jQuery addClass() method adds one or more classes to the selected elements.

					 
        
          $("button").click(function(){
            // add single class "text-red"
            $("h1, h2, p").addClass("text-red");

            // add multiple classes "bg-red text-white"
            $("div").addClass("bg-red text-white");
          });
        
      
jQuery removeClass() Method

The jQuery removeClass() method removes one or more classes from the selected elements.

					 
        
          $("button").click(function(){
            // remove single class "text-red"
            $("h1, h2, p").removeClass("text-red");

            // remove multiple classes "bg-red text-white"
            $("div").removeClass("bg-red text-white");
          });
        
      
jQuery toggleClass() Method

The jQuery toggleClass() method toggles between adding/removing classes from the selected elements.

					 
        
          $("button").click(function(){
            // toggle single class "text-red"
            $("h1, h2, p").toggleClass("text-red");

            // toggle multiple classes "bg-red text-white"
            $("div").toggleClass("bg-red text-white");
          });
        
      
jQuery css() Method

The jQuery css() method sets or returns one or more style properties for the selected elements.

Get A CSS Property
					 
        
          $("p").css("background-color");
        
      
Set A CSS Property
					 
        
          $("p").css("background-color", "yellow");
        
      
Set Multiple CSS Properties
					 
        
          $("p").css({
            "background-color": "yellow",
            "color": "#ffffff",
            "font-size": "200%"
          });
        
      

How you feel about this blog:

Share this blog on:

Report Us

If you find any error in the turtorials, or want to share your suggestion/feedback, feel free to send us email at: info@lynxsia.com

Contact Us
Ads
Logo
Lynxsia IT Solutions

We are concern with various development process like website design & development, E-commerce development, Software development, Application development, SMS & Bulk SMS Provider, PWA Development, and many more..

Kotwali Road, Chhiptehri, Banda, 210001, UP, India

Copyright © 2022, Lynxsia IT Solutions, All rights reserved