Create button where a mouse was clicked - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Input Button

Description

Create button where a mouse was clicked

Demo Code

ResultView the demo in separate window

<html>
   <head></head>
   <body>  
      <script type="text/javascript">
  counter = 1;/*from w  ww  .  j a  v  a  2  s .co  m*/
  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