Advertisement
metalx1000

HTML JavaScript CSS Button Functions

Feb 22nd, 2020
750
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <!DOCTYPE html>
  2. <html lang="en">
  3.   <head>
  4.     <title></title>
  5.     <meta charset="utf-8">
  6.     <meta name="viewport" content="width=device-width, initial-scale=1">
  7.  
  8.     <style>
  9.       .myButton {
  10.         box-shadow: 0px 10px 14px -7px #276873;
  11.         background:linear-gradient(to bottom, #599bb3 5%, #408c99 100%);
  12.         background-color:#599bb3;
  13.         border-radius:8px;
  14.         display:inline-block;
  15.         cursor:pointer;
  16.         color:#ffffff;
  17.         font-family:Arial;
  18.         font-size:20px;
  19.         font-weight:bold;
  20.         padding:13px 32px;
  21.         text-decoration:none;
  22.         text-shadow:0px 1px 0px #3d768a;
  23.       }
  24.       .myButton:hover {
  25.         background:linear-gradient(to bottom, #408c99 5%, #599bb3 100%);
  26.         background-color:#408c99;
  27.       }
  28.       .myButton:active {
  29.         position:relative;
  30.         top:1px;
  31.       }
  32.       </style>
  33.         <script>
  34.           function ready(callback){
  35.             // in case the document is already rendered
  36.             if (document.readyState!='loading') callback();
  37.             // modern browsers
  38.             else if (document.addEventListener) document.addEventListener('DOMContentLoaded', callback);
  39.             // IE <= 8
  40.             else document.attachEvent('onreadystatechange', function(){
  41.               if (document.readyState=='complete') callback();
  42.             });
  43.           }
  44.  
  45.           ready(function(){
  46.             createBtn("Click Me","test","main","cl");
  47.             createBtn("Click Me too","test2","main","cl");
  48.             createBtn("Click Me As Well","test2","main2","cl2");
  49.           });
  50.          
  51.           let cl2 = function(e){
  52.             e.innerHTML=Date();
  53.           }
  54.  
  55.           let cl = function(e){
  56.             console.log(e.innerHTML);
  57.             alert(e.innerHTML);
  58.           };
  59.  
  60.  
  61.           function createBtn(label,id,div,func){
  62.             let btn = '<a href="#" onclick="'+func+'(this);" id="'+id+'" class="myButton">'+label+'</a>';
  63.             document.getElementById(div).innerHTML+=btn;
  64.           }
  65.         </script>
  66.       </head>
  67.       <body>
  68.  
  69.         <div id="main"></div>
  70.         <div id="main2"></div>
  71.  
  72.       </body>
  73.     </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement