Tuesday, October 11, 2011

JQuery Tutorial 1: Showing alert popup

Let me put the code first then we will do the post mortem

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.5.2.js"></script>
<input type="button" value="Trigger Alert" id="btn_trig">
<script type="text/javascript">
/* $('#btn_trig') gives reference to the html element whose id is passed,
 * similiar to getElementById() function. On that reference a callback function is defined
 *  syntax of callback functions is like this event( function(){ //thing you want to do on event happening}). Callback functions are called when event happens.
 alert("Hello World!");

Try for yourself:

1 comment: