Code has been added to clipboard!

The Correct Way to Use jQuery .off() Method

Reading time 1 min
Published Jan 9, 2018
Updated Oct 10, 2019

jQuery off: Main Tips

  • The .off() method makes jQuery remove event listeners from selected elements.
  • If no arguments are specified, jQuery .off() removes all event handlers attached to specified elements.
Udacity
Pros
  • Simplistic design (no unnecessary information)
  • High-quality courses (even the free ones)
  • Variety of features
Main Features
  • Nanodegree programs
  • Suitable for enterprises
  • Paid certificates of completion
Coursera
Pros
  • Professional service
  • Flexible timetables
  • A variety of features to choose from
Main Features
  • Professional certificates of completion
  • University-level courses
  • Multiple Online degree programs
Datacamp
Pros
  • Great user experience
  • Offers quality content
  • Very transparent with their pricing
Main Features
  • Free certificates of completion
  • Focused on data science skills
  • Flexible learning timetable

Usage of .off()

jQuery .off() method removes event handlers added using the .on() method.

Example
$("button").click(() => {
   $("div").off("click");
});

jQuery .off(): Syntax

The syntax for .off() jQuery method is as follows:

$("selector").off(event,selector,handler);

jQuery .off() method takes three arguments:

  • event - an event type to specify what handlers should be removed. Accepts multiple values separated by spaces.
  • selector - a selector, which must match the one used by the .on() method to add the jQuery event handlers you now wish to remove.
  • handler - the name of the function that was run by the specified jQuery event handler.

Latest Udacity Coupon Found:

Verified STAFF PICK

75% OFF COURSES

Udacity Black Friday Offer

The best time to save on Udacity courses is now - follow this coupon to access a 75% Udacity Black Friday discount & enjoy learning at a very low cost!

Expiration date: 30/01/2021
3176 People Used
Only 97 Left
Rating
5.0