How to remove a CSS attribute with jQuery?

21

In jQuery, you can add an attribute to an element by using the attr function. You can also remove an attribute using the removeAttr function.

And when I define an attribute of css through the function $.css ? How do I remove?

    
asked by anonymous 26.01.2016 / 17:29

2 answers

24

The simplest solution would be to zero the element:

$.css("background-color", ""); // exemplo com background-color

Example:

$(function(){
  var contador = 0;
  $(".btn").click(function(){
    if(contador == 0)
    {
      $(this).css("background-color", "blue");
      contador = 1;
    }
    else
    {
      $(this).css("background-color", "");
      contador = 0;
    }
  });
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><buttonclass="btn">Exemplo</button>

Source: StackOverflow

    
26.01.2016 / 17:32
13

Remove a CSS attribute:

$(el).css("color", "");

Remove multiple CSS attributes:

$(el).css({
   "color": "",
   "background-color": "",
   "outline": "",
});
    
26.01.2016 / 17:37