Changing Backgrounds Dynamically On Blogger Using Jquery

I've been quite busy over the past few weeks with my clients and articles on SML. Today, I found sometime to work out a simple trick based on Jquery - Changing Backgrounds Dynamically. Well, I hope you read the article about "Adaptable View On Blogger" wherein, I mentioned we can tweak the design of our blog dynamically. We'll be using the same concept in this article as well...

I don't want to take too much of your time. So, I'll just explain the basics about the working of the script. The script will add or remove classes to the body element based on what list item the user clicks on. That's it. So, take a look at the demo of this simple effect by visting the link below and we'll get started...


1. Navigate to "Design>>Edit HTML" and make a backup of your template by clicking on the "Download full template" link at the top of the page. Once the back up is over, search for the following piece of code.
2. Paste the following piece of code just above the line mentioned step 1.
.bg1 { background: url(BG IMAGE URL) repeat-x; background-color: #6c0000; }
.bg2 { background: url(BG IMAGE URL) repeat-x; background-color: #5A2A00; }
.bg3 { background: url(BG IMAGE URL) repeat-x; background-color: #00345B; }
3. Next, search for the following piece of code.
4. Paste the following piece of code just above the line mentioned in step 3. Save your template.
<script src='' type='text/javascript'/>
<script type='text/javascript'>

        $(&quot;;).click( function(){ $
        (&quot;body&quot;).removeClass(&#39;bg2 , bg3&#39;).addClass(&quot;bg1&quot;);

    $(&quot;li.two&quot;).click( function(){ $
        (&quot;body&quot;).removeClass(&quot;bg1 , bg3&quot;).addClass(&quot;bg2&quot;);

    $(&quot;li.three&quot;).click( function(){ $
        (&quot;body&quot;).removeClass(&quot;bg1 , bg2&quot;).addClass(&quot;bg3&quot;);

Note: You need not paste the first line (highlighted in orange) in the above coding if you already have the jquery file running on your blog.
5. Now, insert the following tags anywhere in your template - may be within the post editor or on  the sidebar or below the content wrapper.
<li class="one"><a href="#">Red</a></li>
<li class="two"><a href="#">Brown</a></li>
<li class="three"><a href="#">Blue</a></li>
6. That's it! Save your template or publish the post. 

Just hit the text of your choice - Red or Brown or Blue and enjoy the changing environment on your blog. You may change from the default colors (Red, Brown, Blue) to the ones you like, by just altering the color codes (highlighted in blue) mentioned in step 2. In fact, you can alter between your background images. To do so, just replace "BG IMAGE URL" with the URL of your background image.

I hope, I kept the logic as well as the post simple. The above code was tested to work fine on all major browsers including, but not limited to, IE, FF, Opera, Chrome and Safari. If you find any difficulties in installing the above effect, then leave a comment or ping me on gtalk. I'll help you out! Do share your opinions about the article via comments:)

Enjoyed the article?
Subscribe to this Blog via Email:

Click here to subscribe to FREE email updates from "Everything About Blogging", so that you do not miss out anything that can be valuable to you and your blog!

    Other Recommended Posts

  • Blogger Tutorials, jQuery
sumera said on August 6, 2011 at 12:50 AM :

thanks for sharing :D was searching for this since long

Mukund said on August 6, 2011 at 1:19 AM :

@sumera: I'm glad that your long term search has come to an end today! Lol:) Thanks for the comment buddy!

Haz Issac said on August 6, 2011 at 2:04 AM :

i will try this.. its is have a text resizer hacks for blogspot? to add every blog post at a tittle post..?

Mukund said on August 6, 2011 at 12:01 PM :

@Haz Issac: I'm not able to understand your English! Just tell me clearly what you want and I'll let you know if it is possible on blogger:)

Analyst said on August 6, 2011 at 11:46 PM :

I must say that it is a great tweak which has been explained in an easy to understand language. You are doing great job.


You got good points there, so I always love your site, it looks like you are an expert in this field. keep up the fantastic work, My friend recommends your blog.

My blog:
rachat credit pret

Mukund said on August 7, 2011 at 10:21 AM :

@Analyst: Ah! Yes! Thanks for the comment buddy! Hope you enjoy the upcoming articles as well!

Mukund said on August 7, 2011 at 10:22 AM :

@Anonymous: Yup! Thanks for the comment and your friend as well who recommends my blog:)

chris said on August 16, 2011 at 7:37 AM :

i really appriciate.god bless

Mukund said on August 16, 2011 at 11:01 AM :

@chris: Well, thanks for the comment buddy! I hope you enjoy the other articles on my blog as well!

benooi said on August 29, 2011 at 8:09 PM :

NICE! Thanks alot

Mukund said on August 29, 2011 at 11:10 PM :

@benooi: Yup! Thanks for the comment buddy!

kk said on October 5, 2011 at 12:26 PM :

changing backgrounds is exactly what i needed, but what is the code for changing 4 to 5 backgrounds

Mukund said on October 7, 2011 at 12:07 AM :

@kk: You just have to extend the codes! If you don't know, how to do that, just hit me via gmail and I'll help you out!

Ricardo said on November 8, 2011 at 6:32 PM :

Seriously, I'm addicted in your tutorials xD.
A while ago I asked you how to add a button to my blog, but I managed to install it after some failed atempts, so I never reached you via e-mail about that. thanks anyway.
I've got a doubt... in fact two about this effect. First off all, Does it only accept 3 choices of Bg change, or can I manually add more and name them "4", "5"... etc.
Second one, let's imagine I want to expand the possibility of changing BG to the possibility of changing between 2/3 or more color schemes, Is it possible?
I will either way use it on my blog, but this questions popped my mind. thanks, and congrats for you amazing tutorials ;)

Mukund said on November 27, 2011 at 11:53 PM :

@Ricardo: Well, sorry for the delayed response! Anyway, it is possible to add more than 3 colors! I'm not clear with the second question! Nevertheless, install the above effect and let me know if you like it!


Is it possible to use several photos, instead of colors/


Use the tab below to comment. No spam please!!!