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.
You can download the jQuery library from the jQuery site or you can use the hosted jQuery library from Google.
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:
<script src="prototype.js"></script> <script src="jquery.js"></script> <script> // Give $ back to prototype.js; create new alias to jQuery. var $jq = jQuery.noConflict(); </script>Use the Argument That's Passed to the jQuery( document ).ready() Function:
<script src="jquery.js"></script> <script src="prototype.js"></script> <script> jQuery(document).ready(function ($) { // Your jQuery code here, using $ to refer to jQuery. }); </script>Creating a different alias for the first loaded jQuery version:
var j = jQuery.noConflict();window.jQuery = j;j("#button172").jqxButton({ width: 150, height: 25 });
The following example demonstrates how jQWidgets work in No-Conflict mode.
<!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 Alias var 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 Alias var 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>