Question:
In jQuery, you can add an attribute to an element via the attr
function. It is also possible to remove an attribute through the removeAttr
function.
And when I set a css
attribute through the $.css
function? How do I remove?
Answer:
The simplest solution would be to reset 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>
<button class="btn">Exemplo</button>
Fonte: StackOverflow