Casa > H > How To Make The Background Image Of A Button Disappear When We Click It, And Make It Appear On Another Button When We Click It In Visual Studio

How to make the background image of a button disappear when we click it, and make it appear on another button when we click it in Visual Studio

It’s fairly simple to do so.
I wrote a some to give you a working example:
Here is the working example on JSFiddle: Button bg-image toggle Example for Quora

I’ve outlined the steps for you:

Add html:

  1. Button 1 
  2. Button 2 

Use css to assign background image to both the buttons.

  1. .bg-img{ 
  2. background-image: url("img.png") 

Add another CSS definition to hide background image:

  1. .hide-bg-img{ 
  2. background-image: none; 

Add your jquery

  1. if($('#bt1').click){ 
  2. $('#bt1').click(function(){ 
  3. $('#bt2').toggleClass('bg-img'); 
  4. $(this).removeClass('bg-img'); 
  5. }); 
  6. }  
  7.  
  8. if($('#bt2').click){ 
  9. $('#bt2').click(function(){ 
  10. $('#bt1').toggleClass('bg-img'); 
  11. $(this).removeClass('bg-img'); 
  12. }); 

This jQuery code can be improved. Read it and try to understand what I did.
When you understand what is happening you can use if/else if/else statement and write for brevity.

Hope this helps.

Here is the JSFiddle working example: Button bg-image toggle Example for Quora

De Fenn Ortizconcepcion

O que é o Pandora One Apk MOD e como as pessoas fazem uso dele? :: Qual é a diferença entre azulejos vidrados e azulejos vitrificados?