-
-
Save mh108/a14d7f8010421f5cf54e to your computer and use it in GitHub Desktop.
Client-Side JavaScript: Event-Handler Demo with jQuery
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang='en'> | |
<head> | |
<meta charset='utf-8' > | |
<title> isEven? </title> | |
</head> | |
<body> | |
<h2>Button Demo with jQuery</h2> | |
<p> | |
Enter a number: | |
<input type="text" id="inputBox" size="12" value=""> | |
</p> | |
<button>isEven?</button> | |
<hr style="width:23%; margin-left:0;"> | |
<div></div> | |
<script src="http://code.jquery.com/jquery-latest.min.js"></script> | |
<script src="client-side-jQ.js"></script> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"use strict"; | |
//function accepts an argument, returns a value | |
function isEven(n){ | |
if(n % 2 == 0) | |
return true; | |
else | |
return false; | |
} | |
//1. define the onclick handler | |
var main = function(){ | |
//get value entered by user in web page | |
var val = $("#inputBox").val(); | |
//display result on web page | |
//caveat: html() won't display booleans | |
$("div").html(String(isEven(val))); | |
}; | |
//2. Select the button and register the handler | |
//button1.on("click", main); | |
$(document).ready($("button").on("click", main)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment