Friday, December 28, 2012

onclick

Event handler onclick (Bubbles: Yes, Cancelable: Yes) terjadi ketika tombol mouse dilepaskan setelah sebelumnya tertekan. Event handler ini valid untuk hampir semua elemen.

Berikut contoh meregister event handler onclick via 'inline model':

<A HREF="#" ONCLICK="alert('Halo saya event handler')">Visit to X.com</A>

Berikut contoh meregister event handler onclick via 'traditional model':

<A ID="anchorID" HREF="#">Visit to X.com</A> <SCRIPT TYPE="text/javascript"> function HandleEvent() { alert("Halo saya event handler"); } document.getElementById("anchorID").onclick=HandleEvent; </SCRIPT>

Berikut contoh meregister event handler onclick via DOM:

<A ID="anchorID" HREF="#">Visit to X.com</A> <SCRIPT TYPE="text/javascript"> function HandleEvent() { alert("Halo saya event handler"); } var anchorElem=document.getElementById("anchorID"); anchorElem.addEventListener("click", HandleEvent, false); </SCRIPT>