How can I add loading spinner on button onlick

bootstrap loading spinner on button click
page loader on button click
button click loader jquery codepen
onclick loading spinner
bootstrap loading spinner overlay
jquery loading spinner
bootstrap 3 spinner
add spinner to button jquery

I have an input. Let's get that code

<div id="demo2"></div>

<script type="text/javascript">
	
function myFun() {
 var a = document.getElementById("demo").value ;
 document.getElementById("demo2").innerHTML = a ;
}


</script>
<input type="text" id="demo"/>
<button onclick="myFun()">Click Me </button>

It's easy. You can do something like the following:

    var buttonElem = document.querySelector('.button');
    
    buttonElem.addEventListener("click", function() {
      buttonElem.classList.add('spinning');
 
      setTimeout( 
            function  (){  
                buttonElem.classList.remove('spinning');
          
            }, 6000);
    }, false);
   
.button {
  display: inline-block;
  outline: none;
  padding: 10px 20px;
  background: #444;
  border-radius: 4px;
  color: #fff;
  border: 0;
  position: relative;
  transition: padding-right 0.3s ease;
  box-shadow: 0 1px 0 #6e6e6e inset, 0px 1px 0 #3b3b3b;
}
.button.spinning {
  padding-right: 40px;
}
.button.spinning:after {
  content: "";
  right: 6px;
  top: 50%;
  width: 0;
  height: 0;
  position: absolute;
  border-radius: 50%;
  -webkit-animation: rotate360 0.5s infinite linear, exist 0.1s forwards ease;
          animation: rotate360 0.5s infinite linear, exist 0.1s forwards ease;
}
.button.spinning:before {
  content: "";
  width: 0px;
  height: 0px;
  border-radius: 50%;
  right: 6px;
  top: 50%;
  position: absolute;
  border: 2px solid #000000;
  border-right: 3px solid #27ae60;
  -webkit-animation: rotate360 0.5s infinite linear, exist 0.1s forwards ease;
          animation: rotate360 0.5s infinite linear, exist 0.1s forwards ease;
}
@-webkit-keyframes rotate360 {
  100% {
    -webkit-transform: rotate(360deg);
            transform: rotate(360deg);
  }
}
@keyframes rotate360 {
  100% {
    -webkit-transform: rotate(360deg);
            transform: rotate(360deg);
  }
}
@-webkit-keyframes exist {
  100% {
    width: 15px;
    height: 15px;
    margin: -8px 5px 0 0;
  }
}
@keyframes exist {
  100% {
    width: 15px;
    height: 15px;
    margin: -8px 5px 0 0;
  }
}
<button class="button">Click Me</button>

How To Create Loading Buttons, Add font awesome icons to buttons (note that the fa-spin class rotates the icon) --​> <button class="buttonload"> <i class="fa fa-spinner fa-spin"></i>Loading Adding a Loading Spinner to a Button with Blazor I’ve been playing with Blazor for several weeks now, and it’s fantastic. For the uninitiated, Blazor allows you to write .NET code that runs in the browser through the power of WebAssembly (Wasm) .

bellow code will help you out, the spinner loads before the content is displayed and when content is ready to display, the spinner is removed.

function myFun() {
  var a = document.getElementById("demo").value;
  document.getElementById("demo2").innerHTML = "";
  document.getElementById("demo2").classList.add("loader");
  setTimeout(function() {
    document.getElementById("demo2").classList.remove("loader");
    document.getElementById("demo2").innerHTML = a;
  }, 2000);
}
.loader {
  border: 6px solid #f3f3f3;
  border-radius: 50%;
  border-top: 6px solid #3498db;
  width: 20px;
  height: 20px;
  -webkit-animation: spin 2s linear infinite;
  /* Safari */
  animation: spin 2s linear infinite;
}


/* Safari */

@-webkit-keyframes spin {
  0% {
    -webkit-transform: rotate(0deg);
  }
  100% {
    -webkit-transform: rotate(360deg);
  }
}

@keyframes spin {
  0% {
    transform: rotate(0deg);
  }
  100% {
    transform: rotate(360deg);
  }
}
<div id="demo2"></div>

<input type="text" id="demo" />
<button onclick="myFun()">Click Me </button>

Button Loading Animation on Click Using JQuery, buttonLoading #LoadingAnimation #buttonloadereffect Hello Friends, In this video i am creating Duration: 6:01 Posted: May 25, 2019 This video explains how to add a spinner for buttons when a user is performing an action. This will help you prevent users from clicking the button twice before performing the actual action.

this is another example when you can use the spinner in middle of the page and use two functions in one

<!DOCTYPE html>
    <html>
    <head>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <style>
    /* Center the loader*/
    .loader {    
      position: absolute;
      left: 50%;
      top: 50%;
      z-index: 1;
      width: 150px;
      height: 150px;
      margin: -75px 0 0 -75px;
      border: 16px solid #f3f3f3;
      border-radius: 50%;
      border-top: 16px solid blue;
      width: 120px;
      height: 120px;
    
      border-right: 16px solid green;
      border-bottom: 16px solid red;
      -webkit-animation: spin 2s linear infinite;
      animation: spin 2s linear infinite;
    }
    
    @-webkit-keyframes spin {
      0% { -webkit-transform: rotate(0deg); }
      100% { -webkit-transform: rotate(360deg); }
    }
    
    @keyframes spin {
      0% { transform: rotate(0deg); }
      100% { transform: rotate(360deg); }
    }
    
    
    
    
    </style>
    </head>
    <body>
    
      <div id="demo2"></div>
    
      <input type="text" id="demo"/>
      <button onclick="myFunction()">Click Me </button>
    
    <script>
    var myVar;
    function myFunction() {
    
      myVar = document.getElementById("demo").value;
      document.getElementById("demo2").innerHTML = "";
      document.getElementById("demo2").classList.add("loader");
         setTimeout(showPage, 3000);
    
    }
    
    function showPage() {
    
        document.getElementById("demo2").classList.remove("loader");
        document.getElementById("demo2").innerHTML = myVar;
        document.getElementById("demo").value = "";
    
    }
    </script>
    
    </body>
    </html>

Bootstrap Button Loading, <button type="button" class="btn btn-primary btn-lg " id="load1" data-loading-text​="<i class='fa fa-circle-o-notch fa-spin'></i> Processing Order">Submit Order</​button>. 3 id="load2" data-loading-text="<i class='fa fa-spinner fa-spin '></i> Processing Order">Submit Order</button>. 6. </div> $('.btn').on('click', function​() {. Hello friends in this video you will learn how you can use spinner. 1. set data to the spinner dynamically. 2.perform action on item selected from the spinner drop down. 3. display result into

Loading spinner with animation · Stephan Wagner, In this article we are making the spinners even nicer by adding a zoom-in and zoom-out animation to it. The code. Check out the following fiddle which has all the  Loading content into a Spinner has nothing to do with click events, any more than generating a Web page has anything to do with somebody clicking a link on the page itself once loaded in a browser. I have no idea what you think "eagerly" is.

Loading Buttons / Pure CSS Button that Loads, Loading Buttons. Bootstrap compatible, pure CSS loading indicator for your button the button: Click Me. <div class="btn btn-primary ld-ext-right" onclick="​this. Icon Bar Menu Icon Accordion Tabs Vertical Tabs Tab Headers Full Page Tabs Hover Tabs Top Navigation Responsive Topnav Navbar with Icons Search Menu Search Bar Fixed Sidebar Side Navigation Responsive Sidebar Fullscreen Navigation Off-Canvas Menu Hover Sidenav Buttons Sidebar with Icons Horizontal Scroll Menu Vertical Menu Bottom Navigation Responsive Bottom Nav Bottom Border Nav Links Right Aligned Menu Links Centered Menu Link Equal Width Menu Links Fixed Menu Slide Down Bar on Scroll Hide

Spinners · Bootstrap, Indicate the loading state of a component or page with Bootstrap spinners, built entirely <div class="spinner-border text-primary" role="status"> <span Use spinners within buttons to indicate an action is currently processing or taking place. This way we can show the loading image while your webpage is loading and while an image is completely loaded. I hope this simple preloader will help you improve your site’s user experience. If you get any difficulty using the codes to your website then do comment below.

Comments
  • Do search before you ask!