Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

179
Views
jQuery test for whether an object has a method?

Is it possible to test whether a jQuery object has a particular method? I've been looking, but so far without success. Thanks!

over 4 years ago · Santiago Trujillo
3 answers
Answer question

0

This should work:

if (!!$.prototype.functionName)
over 4 years ago · Santiago Trujillo Report

0

Because jQuery methods are prototype into a jQuery object, you can test it from the prototype object.

if( $.isFunction( $.fn.someMethod ) ) {
    // it exists
}

This uses the jQuery.isFunction()[docs] method to see if $.fn.someMethod is indeed a function. (In jQuery jQuery.fn is a reference to the prototype object.)

over 4 years ago · Santiago Trujillo Report

0

try

if ($.fn.method) {
    $('a').method(...);
}

or

if ($.method) {
    $.method(...);
}
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!