Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9219609
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T03:09:16+00:00 2026-06-18T03:09:16+00:00

I am working on a demo panel which should switch two different background images.

  • 0

I am working on a demo panel which should switch two different background images.
you click on one link and two css classes are changed.
the link contains data-field=”bg1″ and this value needs to change the css class: top-bg0 and bottombg0.

Here is a fiddle setup:
http://jsfiddle.net/wpcustoms/ktD3f/

can somebody please assist me with the javascript?

that`s what I came up so far:

$('.panel ul li a').click(function(){
    var bgname = $(this).data('bg');
    $('#headerbar').removeClass('top-bg0').toggleClass(bgname);
    $('#footerbar').removeClass('bottom-bg0').toggleClass(bgname);
});

it currently removes the top-bg0 part and replaces it with the data-field (bg1,2,3) clicking on another link adds another class so it ends up with class=”bg1 bg2 bg3″ instead of changing the top-X and bottom-X value. Is there a way to FIND something in a class string and replace it?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T03:09:17+00:00Added an answer on June 18, 2026 at 3:09 am

    If your two elements only have the one class each, then you could simply use the no argument version of .removeClass() to remove whatever the current class is, then add the correct one:

    $('.settings-panel .bg_pattern ul li').click(function(){
        var bgname = $(this).data('bg');
        $('#headerbar').removeClass().addClass('top-' + bgname);
        $('#footerbar').removeClass().addClass('bottom-' + bgname);
    });
    

    Updated jsFiddle demo

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want a working demo of table pagination. Can some one give me link
Working demo CLick $(document).ready(function(e) { $('span#pijlr, span#pijll').show(); $('#gallery').css('overflow','hidden'); $('span#pijlr').click(function(e) { if (!$('#gallcont').is(':animated')) { var
I'm working with a demo of two sortable jquery lists... but have a problem
I have the working demo is in this link . The markup is something
I'm working on application which is drawing on Canvas similar to Finger Paint demo
I want a sample working demo or link to understand the database functions like
HI, I have a flash application (working demo here ) which I'm using to
I have multiple buttons on one page. WHen you click a button, a panel
Working Demo: http://jsbin.com/opokev/54 I'm working on having this image as the background image and
I'm working through the Demo: Binding Data with the SqlDataSource of this pluralsight video

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.