Set button CSS style position to fixed - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Button

Description

Set button CSS style position to fixed

Demo Code

ResultView the demo in separate window

<html>
   <head></head>
   <body>  
      <script type="text/javascript">
  counter = 1;//from  w ww .j a va 2s  .c om
  document.onclick = function(e) {
    var button = document.createElement('button');
    button.style.position = 'fixed';
    button.style.left = e.pageX + 'px';
    button.style.top = e.pageY + 'px';
    button.innerHTML = counter;
    counter++;
    document.body.appendChild(button);
    setTimeout(function() {
      document.body.removeChild(button);
    }, 1000);
  };

      </script> 
   </body>
</html>

Related Tutorials