Reputation: 63
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
Reputation: 7249
Just in case you have removeAttr , you may remove all styles definitions with:
$('h1').removeAttr('style');
Upvotes: 0
Reputation: 63
<script>
$(document).ready(function(){
$("h1").each(function( index ) {
$("."+$(this).attr("class")).css({"background":"none"});
});
});
</script>
Upvotes: 3
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