Events Basics
by Ivan Gerasimenko
HTML
<h4>In html onclick="alert('Hello!')"</h4>
<input type="button" value="say Hello from click" onclick="alert('Hello!');" />
<h4>In html onclick="sayHello()" call function</h4>
<input type="button" value="call sayHello() from click" onclick="sayHello()" />
<h4>Attach event in js code</h4>
<input type="button" value="attach sayHello() in code" id="button-attach-event" />
JavaScript
function sayHello(msg) {
msg = msg === undefined ? '' : msg;
alert('Hello from sayHello() function. ' + msg);
}
$(function() {
$("#button-attach-event").on("click", function() { sayHello("attached event") });
});