Avatar of oggiemc
oggiemc
Flag for Ireland asked on

javascript event handlers

Can someone explain whats happening in the followong lines of code, taken from the application attached..

var $ = function ( id ) {
return document.getElementById( id );
}
$("btnDisplay").onclick = display_click;           // In particular, what is going on here??

Thanks
head>
<title>JavaScript Event Handler</title>
<script type="text/javascript">
// This function receives an id and gets the related XHTML object.
var $ = function ( id ) {
return document.getElementById( id );
}
var display_click = function () {
alert( "You clicked the button.");
}
window.onload = function () {
$("btnDisplay").onclick = display_click;
}
</script>
</head>
<body>
<p><input type="button" value="Display Message" id="btnDisplay" /></p>
</body>
</html>

Open in new window

JavaScript

Avatar of undefined
Last Comment
leakim971

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
leakim971

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck