jQuery Objects

jQuery Objects

  • Whenever we use $() or jQuery() to target an element, a jQuery object is created

    • For example $('p') creates a jQuery object that targets all <p> elements on a page
  • jQuery objects can be stored in variables in the same way we are already familiar with

    • It is a best practice to prepend a $ to the name of any variable that holds a jQuery Object:
  // store jQuery object into a variable named "$mainMenu"
  $mainMenu = $('#main-menu')

  // call a jQuery methods `.hide()` on jQuery object to hide the targeted element
  $mainMenu.hide()