How to use onclick property to run click event on an element in JavaScript

1 Answer

0 votes
<!DOCTYPE html>
<html>
<head>
<script type="text/JavaScript"> 
function initEvent() 
{
  var sp = document.getElementById("span_id");
  sp.onclick = show_onclick;
};

function show_onclick() 
{
  alert("onclick Event on span_id")
}
</script>
</head>
<body onload="initEvent();">
<span id="span_id">Click Here</span>
</body>
</html>

 



answered Jun 11, 2016 by avibootz
...