jQuery

The Javascript library jQuery simplifies client-side scripting, event management, and animation in clients. Its simple syntax is designed to select HTML elements and perform an action on them.

Review its syntax below:

$(selector).action()

The $ sign accesses jQuery, the selector accesses the element, and the action specifies what to do with the element.

USING jQUERY

Visual Studio includes the jQuery library as a standard library. Access jQuery by clicking the Scripts folder in Visual Studio, selecting Add existing item, and choosing the jQuery library. The library can also be included through a standard declaration in the head of HTML markup:

<script type=”text/javascript” src="/scripts/jquery-
     2.1.0.min.js"></script>

Then simply include standard jQuery statements in the body of markup. Review the sample code below (assume a submit button exists):

<script type="text/javascript">
$(document).ready(function() {
	$("#SubmitButton").click(function() {
		alert("jQuery provides this alert");
	});
});
</script>

The library provides interactivity resembling AJAX without employing server controls. It also offers simple and easy-to-interpret code.

The jQuery library also provides another validation option. Standard ASP.NET validation controls provide rather simple client-side code in contrast to validation offered by jQuery. The validation offered by jQuery allows for deeper control.

The code generated by ASP.NET is viewed as a bit sloppy and difficult to use client-side libraries on, however, mixing jQuery with the code solves this problem.

In some situations, replacing AJAX controls, like a control used for a popup, with jQuery proves the better option because jQuery offers a much larger range of packaged and optimized functionalities.