jQuery is a JavaScript Library that simplifies HTML document traversing, event handling and Ajax interactions for web development. jQuery provides an easy way to select and work with HTML elements as a group or as a single element.
<head><script type="text/javascript" src="jquery-1.11.1.min.js"></script><script async src="https://www.googletagmanager.com/gtag/js?id=G-2FX5PV9DNT"></script><script>window.dataLayer = window.dataLayer || [];function gtag(){dataLayer.push(arguments);}gtag('js', new Date());gtag('config', 'G-2FX5PV9DNT');</script></head>
You can download the jQuery library from the jQuery site or you can use the hosted jQuery library from Google.
<head><script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script><script async src="https://www.googletagmanager.com/gtag/js?id=G-2FX5PV9DNT"></script><script>window.dataLayer = window.dataLayer || [];function gtag(){dataLayer.push(arguments);}gtag('js', new Date());gtag('config', 'G-2FX5PV9DNT');</script></head>
The jQuery syntax is made for selecting HTML elements and perform some action on
the element(s).
$(selector).action()
A dollar sign to define jQuery.
A (selector) to "query (or find)" HTML elements.
A jQuery action() to be performed on the element(s).
jQuery CSS selectors can be used to change CSS properties for HTML elements.
The following example changes the background-color of all div elements to black:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html lang="en"><head> <script type="text/javascript" src="../../scripts/jquery-1.11.1.min.js"></script> <script type="text/javascript"> $(document).ready(function () { $("button").on('click', function(){ alert("Button is Clicked."); }); }); </script><script async src="https://www.googletagmanager.com/gtag/js?id=G-2FX5PV9DNT"></script><script>window.dataLayer = window.dataLayer || [];function gtag(){dataLayer.push(arguments);}gtag('js', new Date());gtag('config', 'G-2FX5PV9DNT');</script></head><body> <button> Click me</button></body></html>
<script src="prototype.js"></script>Use the Argument That's Passed to the jQuery( document ).ready() Function:<script src="jquery.js"></script><script>// Give $ back to prototype.js; create new alias to jQuery.var $jq = jQuery.noConflict();</script>
<script src="jquery.js"></script>Creating a different alias for the first loaded jQuery version:<script src="prototype.js"></script><script>jQuery(document).ready(function ($) {// Your jQuery code here, using $ to refer to jQuery.});</script>
var j = jQuery.noConflict();The following example demonstrates how jQWidgets work in No-Conflict mode.window.jQuery = j;j("#button172").jqxButton({ width: 150, height: 25 });
<!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml"><head><title>jQWidgets in No-Conflict mode</title><link rel="stylesheet" href="../../jqwidgets/styles/jqx.base.css" type="text/css" /><!-- load jQuery 1.10.2 --><script type="text/javascript" src="../../scripts/jquery-1.10.2.min.js"></script><script type="text/javascript">//Create a New Aliasvar jQuery_1_10_2 = jQuery.noConflict();</script><!-- load jQuery 1.11.1 --><script type="text/javascript" src="../../scripts/jquery-1.11.1.min.js"></script><script type="text/javascript">//Create a New Aliasvar jQuery_1_11_1 = jQuery.noConflict();if (!window.jQuery) window.jQuery = jQuery_1_11_1;</script><script type="text/javascript" src="../../jqwidgets/jqxcore.js"></script><script type="text/javascript" src="../../jqwidgets/jqxbuttons.js"></script><script type="text/javascript" src="../../scripts/demos.js"></script><script type='text/javascript'>jQuery_1_11_1(document).ready(function ($) {// Create jqxButton$("#jqxbutton1111").jqxButton({ width: 150, height: 25 });$("#jqxbutton1111").on('click', function () {alert($.fn.jquery);})});</script></head><body><div id='content'><div style='width: 150px;' id='jqxWidget'><div><input type="button" value="Use jQuery 1.11.1" id='jqxbutton1111' /></div></div></div></body></html>