javascript inline onclick code example
Example 1: how to add onclick event in javascript
var element = document.getElementById("elem");
element.onclick = function(event) {
console.log(event);
}
Example 2: javascript onclick get event
<div onclick="doSomething(event,this)"></div>
<script>
function doSomething(e,el){
e = e || window.event;
console.log(e);
console.log(el);
}
</script>
Example 3: onclick a tag
<a href='http://www.google.com' onclick='return check()'>check</a>
<script type='text/javascript'>
function check() {
return false;
}
</script>