Событие <onmousedown>

Событие onmousedown по своему действию похоже на onclick и отличается от него тем, что срабатывает в момент нажатия на кнопку мыши. onclick же в каком-то смысле является комбинацией событий onmousedown и onmouseup.

поддержка браузерами:
IExplorerChromeOperaSafariFirefoxAndroidiOS
4.0+1.0+4.0+1.0+1.0+1.0+1.0+
синтаксис:
onmousedown="скрипт"
значения:

Код скрипта

значение по умолчанию:

Нет

применяется к тегам:

<a>, <abbr>, <acronym>, <address>, <applet>, <area>, <b>, <basefont>, <bdo> <bgsound>, <big>, <blockquote>, <body>, <br>, <button>, <caption>, <center>, <cite>, <code>, <col>, <colgroup>, <dd>, <del>, <dfn>, <dir>, <div>, <dl>, <dt>, <em>, <embed>, <fieldset>, <font>, <form>, <frame>, <h1>, <h2>, <h3>, <h4>, <h5>, <h6>, <hr>, <i>, <iframe>, <img>, <input>, <ins>, <isindex>, <kbd>, <label>, <legend>, <li>, <link>, <map>, <marquee>, <menu>, <nobr>, <object>, <ol>, <option>, <p>, <plaintext>, <pre>, <q>, <s>, <samp>, <select>, <small>, <span>, <strike>, <strong>, <sub>, <sup>, <table>, <tbody>, <td>, <textarea>, <tfoot>, <th>, <thead>, <tr>, <tt>, <u>, <ul>, <var>, <wbr>, <xmp>

пример кода:
<!DOCTYPE HTML>
<html>
 <head>
  <meta charset="utf-8">
  <title>Событие onmousedown</title>
  <script>
   var i = 0; 
   function counter(){
    i++;
    document.getElementById("layer2").innerHTML += i + " ";
   }
  </script>
  <style type="text/css">
   #layer1 {
    background: #fc0; /* Цвет фона */
    padding: 30px 10px; /* Поля вокруг текста */
   }
  </style>
 </head>
 <body onmouseup="if(window.interval) clearInterval(interval)">
   <div id="layer1" onmousedown="interval=setInterval('counter()',50)">
    Щелкните внутри
   </div>
   <div id="layer2"></div>
 </body>
</html>
примечание:

В данном примере при наведении курсора на оранжевый слой и нажатии на кнопку мыши выводятся числа, до тех пор, пока кнопка не будет отпущена.