• Home
  • Save code
  • Refresh
  • theme1 theme2 dark3
  • Embed
  • DMCA

How to insert icon in button using JavaScript dynamically

<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css"/>
 
<button id="myButton" onclick="addIcon()"> Click Me</button>
 <script> 
function addIcon(){
 btn = document.getElementById('myButton');
 btn.innerHTML = '<i class = "fa fa-spinner fa-spin"></i> Please wait...';
 
 setTimeout(function(){ 
   alert("Completed!"); 
   btn.innerHTML = 'Click Me';
 }, 3000); 
 
}
</script>
 
 

You may like these posts :

  1. Remove objects with the same ID from an array in JavaScript
  2. html code: search box to find texts on the pages
  3. Preserve-3d Example in CSS CodePen
  4. How to upload multiple image in html and display a preview
  5. Stylish search box in HTML CSS code
  6. Removing elements with array map in javascript example
  7. Top 5 stylish buttons with icon in html & css
  8. Multiple Choice Quiz App Using JavaScript

Write Your Comment