Shanmugam
Shanmugam

Reputation: 63

how to remove the background image using jquery with class name

I'm trying to remove the background image using jquery.But its not happening, But using the same format i can change the background color

<html>
<head>
<style>
h1 
{
background-image:url('paper.gif');
background-color:#cccccc;
}
</style>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script>
$(document).ready(function(){

     $("h1").each(function( index ) {
    $("."+$(this).attr("class")).css('background-image' , 'none');

    });

});
</script>
</head>


<h1 class="RED">This is a heading</h1>
<h1 class="YELLOW">This is a heading</h1>
<h1 class="RED">This is a heading</h1>
</html>

Upvotes: 3

Views: 12957

Answers (4)

S&#233;rgio
S&#233;rgio

Reputation: 7249

Just in case you have removeAttr , you may remove all styles definitions with:

$('h1').removeAttr('style');

Upvotes: 0

Shanmugam
Shanmugam

Reputation: 63

<script>
$(document).ready(function(){



     $("h1").each(function( index ) {
     $("."+$(this).attr("class")).css({"background":"none"});



    });

});
</script>

Upvotes: 3

malkam
malkam

Reputation: 2355

try this

$('h1').css('background-image', 'none');

Upvotes: 0

Aaron
Aaron

Reputation: 435

You don't need the class part, try this:

<script>
$(document).ready(function() {
    $("h1").css({'background-image' , 'none'});
});
</script>

In jQuery, you aren't modifying the stylesheet, you are modifying the DOM after the stylesheet has been applied, so just attack the element directly.

Upvotes: 5

Related Questions