Example
Click Me
Click me for inline onclick event
<!DOCTYPE html>
<html>
<head>
<title>onClick Demo</title>
</head>
<body>
<h1 id="clickHeadline">Click Me</h1>
<h1 id="onclickHeadline" onclick="clickInline()">Click me for inline onclick event</h1>
<script>
//annonymous function
var headline = document.getElementById("clickHeadline");
headline.onclick = function() {
headline.innerHTML = "CLICKED!";
};
// using onclick event in html h1 to change headline
var onclickHeadline = document.getElementById("onclickHeadline");
function clickInline() {
onclickHeadline.innerHTML = "CLICKED!";
}
</script>
</body>
</html>
Most Helpful This Week
jQuery Show or Hide text on button click
How to build simple tabs with jQuery?
JavaScript HTML5 Validation for name and email field
JavaScript sort multi dimensional array on specific columns
Check if a string ends with the given target string
Write a function that splits an array into groups the length of size and returns them as a two-dimensional array