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 8889933
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T22:23:05+00:00 2026-06-14T22:23:05+00:00

I want to make 4 buttons that are: when you click on it,the one

  • 0

I want to make 4 buttons that are:
when you click on it,the one chosen, its background-image changed, the other 3 remain the original background image unless user hover it ,while user hover the buttons it changes its background-image .

If I only use :hover, or :active,after clicked,the background image will revert to original when I release mouse,or just moved away mouse, if I use click function, after it changed background image it cannot be revert or have to type a long piece codes to control it.What is the simplest way to make these 4 buttons?

I tried this: abit clumsy, I have :hover in css, but it is actually missing the hover effect for this code

$s_btn_1.on('click',function() {
        if (chosen!=1){
            chosen = 1; 
            console.log('chosen');
        $.get("services_1.php", function(data){
         // $service_box.html(data);

        }); 

        return_default();

        $folder1.css('background',"url('images/services/btn1_hover.png')");
        $folder1.css('background-size',"100% 100%");

    }

    });

  $s_btn_2.on('click',function() {
        if (chosen!=2){
            chosen = 2;
            console.log('chosen');

            $.get("services_2.php", function(data){
        //      $service_box.html(data);
            });
            return_default();

            $folder2.css('background',"url('images/services/btn2_hover.png')");
            $folder2.css('background-size',"100% 100%");
        }
    });

    $s_btn_3.on('click',function() {
        if (chosen!=3){
            chosen = 3;
            return_default();

            $folder3.css('background',"url('images/services/btn3_hover.png')");
            $folder3.css('background-size',"100% 100%");
        }
    });

    $s_btn_4.on('click',function() {
        if (chosen!=4){
            chosen = 4;
            return_default();

            $folder4.css('background',"url('images/services/btn4_hover.png')");
            $folder4.css('background-size',"100% 100%");
        }
    });
  //$("#service_btn").addClass(".folder1_hover");
    function return_default(){
        $folder1.css('background-image',"url('images/services/btn1.png')");
        $folder2.css('background-image',"url('images/services/btn2.png')");
        $folder3.css('background-image',"url('images/services/btn3.png')");
        $folder4.css('background-image',"url('images/services/btn4.png')");
        $folder1.css('background-size',"100% 100%");
        $folder2.css('background-size',"100% 100%");
        $folder3.css('background-size',"100% 100%");
        $folder4.css('background-size',"100% 100%");
    }
});
  • 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-14T22:23:06+00:00Added an answer on June 14, 2026 at 10:23 pm

    I just finished my aim so I post my code here, I think it is the simplest way,and clear

    $(document).ready(function() {   
         var btns = {
             'bg_o' : ['images/services/btn1.png','images/services/btn2.png','images/services/btn3.png','images/services/btn4.png'],
             'bg_h' : ['images/services/btn1_hover.png','images/services/btn2_hover.png','images/services/btn3_hover.png','images/services/btn4_hover.png'],
             '$all_btn' : $('.all_btn'),
             '$folders':[$('#folder1'),$('#folder2'),$('#folder3'),$('#folder4')],
             'folders_status':new Array('inactive','inactive','inactive','inactive')
             ,jquery_func : function(){
                btns.$all_btn.each(function(){
                    $(this).click(function(){
                        for(i=0;i<4;i++){
                            var imageurl_o = new Array();
                            imageurl_o[i] = {'background-image':'url('+btns.bg_o[i]+')'};       
                            btns.$folders[i].css(imageurl_o[i]);    
                            btns.folders_status[i]='inactive';
                        }
                        for(i=0;i<4;i++){           
                            var myparent = btns.$folders[i].parent();                       
                            if($(this).attr('class') == myparent.attr('class')){
                                var imageurl_h = {'background-image':'url('+btns.bg_h[i]+')'};
                                btns.$folders[i].css(imageurl_h);   
                                btns.folders_status[i]='active';
                            }   
                        }
                    });
                    $(this).mouseover(function(){
                        for(i=0;i<4;i++){
                            var imageurl_o = new Array();
                            imageurl_o[i] = {'background-image':'url('+btns.bg_o[i]+')'};
                            if(btns.folders_status[i]=='inactive')
                            btns.$folders[i].css(imageurl_o[i]);    
                        }
                        for(i=0;i<4;i++){           
                            var myparent = btns.$folders[i].parent();                       
                            if($(this).attr('class') == myparent.attr('class')){
                                var imageurl_h = {'background-image':'url('+btns.bg_h[i]+')'};
                                btns.$folders[i].css(imageurl_h);   
                            }   
                        }
    
                    });
                }); 
             }
         }
         btns.jquery_func();
    });  
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to make a button that starts my php script after I click
I've got some Buttons that I want to make un-clickable (but still appear on
I have a button that I want to make disappear if anything is tapped
i want to make a dynamic list with buttons on it. My button in
I want to make an extension method which fills a stackpanel with buttons. In
i want to make fake progress bar when i click on the button: for
I want to make a simple table that contains a custom button in a
I'm using System.Windows.Forms.ContextMenu. I want to make it so when you click some of
I have 2 NSButtons, Both IBActions. When I click one of the buttons, I
I want to make preview button as usual form button next to submit button(as

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.