Array
University of Oregon

jQuery

jquerylogo256

What Is JQuery?

jQuery is a JavaScript library (i.e. written in JavaScript) designed to simplify the scripting of the DOM-API across all browsers (“write once/run everywhere”).

The jQuery library is used by more than 61 percent of the top 100,000 sites.

jQuery’s CDN serves about 20 terabytes of data on an average day (7 petabytes/year).

Learn jQuery

Load the Latest Version of jQuery

Use this script element to load the latest from jQuery’s Content Delivery Network (CDN):

 <script src="http://code.jquery.com/jquery-latest.min.js"></script>

Replace .value, .innerHTML, .textContent, and .src with jQuery Functions

.html(). Get the HTML contents of a container element.
.html(htmlString). Set the HTML contents of a container.

$(“main”).html(“<p>Delta Echo Foxtrot</p>”);   //set
console.log($(“main”).html());   //get

jQuery also has a similar function called .text() that only alters text without adding tags. This function will not evaluate any HTML tags passed to it.

.val(). Get the value attribute of DOM elements, such as textboxes.
.val(value). Set the value of an element.

$(“#outBox”).val(“Golf Hotel”);    //set
console.log($(“#outBox”).val());  //get

$(“#img2”).attr(“src”, “../images/img-name.png”); //set

Replace onclick with .on()

.on() 
Description: Attach an event handler function for an event.

Example:

 $(‘#btn1’).on(“click”, function(){ console.log(“clicked!”); })

Learn More jQuery

Skip to toolbar