Gordon Gordon - 23 days ago 10
CSS Question

jquery, how to remove button colour after it has been pressed?

<button style="background-color:lightblue" id="extractv">
<b>
Extract<br>v
</b>
</button>
...

$("#extractv").click(function () {
$("#extractv").removeAttr("style");
});


After someone clicks on the button, I want to remove the background color on the button. I am not sure why it's not working.

Thanks

Gordon

Answer

I'm not exactly sure why the code you posted doesn't work but the following will do the trick

$(document).ready(function() {
    $('#extractv').click(function() {
       $(this).removeAttr('style');
    }); 

});

jsfiddle version: http://jsfiddle.net/UUxHJ/

As others have pointed out though it's better (more future-proof) here to only remove the background-color versus completely taking out the style attribute.

$('#extractv').click(function() {
   $(this).css('background-color','');
}); 
Comments