jQuery Syntax

$() function

  • jQuery uses a built-in function called jQuery() to allow developers to programmatically select elements on a html page

  • $() is shorthand for jQuery()

    • This shorthand syntax is used almost exclusively (because results in less typing) and that is what we will be using throughout the course
  // programmatically "select" all p tags on the page using jQuery() syntax
  jQuery('p')
  

is the same as:

  // programmatically "select" all p tags on the page using the $() shorthand syntax; most widely used approach
  $('p')
  

Example

We will be using the shorthand syntax throughout this course:

// Use jQuery to "select" an element with an id of main and listen for a click event

$("#main").click(doSomething)