Wednesday, May 9, 2018

pure javascript click by id

Here i give you code of pure javascript.

You can add any event by id.

Simple, copy and post this code in any file and you will get result.

<button id="chirag">Button 1</button> <br>
<button id="2">Button 2</button> <br>
<button id="3">Button 3</button> <br>

<script type="text/javascript">
var reply_click = function()
{
    alert("Button clicked, id "+this.id+", text"+this.innerHTML);
}
document.getElementById('chirag').onclick = reply_click;
document.getElementById('2').onclick = reply_click;
document.getElementById('3').onclick = reply_click;
</script>