JQuery | isFunction() method
This isFunction() Method in jQuery is used to determines if its argument is callable as a function.
Syntax:
jQuery.isFunction( value )
Parameters: The isFunction() method accepts only one parameter that is mentioned above and described below:
- value : This parameter is the value to be tested.
Return Value: It returns the boolean value.
Below examples illustrate the use of isNumeric() method in jQuery:
Example 1: In this example, the isFunction() method checks an value to see if it’s a Function.
<!DOCTYPE html> < html > < head > < meta charset = "utf-8" > < title >JQuery | isFunction () method</ title > < script src = "https://code.jquery.com/jquery-3.4.1.js" ></ script > </ head > < body style = "text-align:center;" > < h1 style = "color: green" > w3wiki </ h1 > < h3 >JQuery | isFunction () method</ h3 > < b >Check the function() {} is a function or not. </ b > < br > < p ></ p > < script > //function() {} $( "p" ).append("" +$.isFunction(function() {})); </ script > </ body > </ html > |
Output:
Example 2: In this example, the isFunction() method also checks an value to see if it’s a Function.
<!DOCTYPE html> < html > < head > < meta charset = "utf-8" > < title >JQuery | isFunction () method</ title > < script src = "https://code.jquery.com/jquery-3.4.1.js" ></ script > </ head > < body style = "text-align:center;" > < h1 style = "color: green" > w3wiki </ h1 > < h3 >JQuery | isFunction () method</ h3 > < b >Check the following are the function or not. </ b > < br >< br > < div >jQuery.isFunction( Beginner[ 0 ] ) = < span ></ span ></ div > < div >jQuery.isFunction( Beginner[ 1 ] ) = < span ></ span ></ div > < div >jQuery.isFunction( Beginner[ 2 ] ) = < span ></ span ></ div > < script > function stub() {} var Beginner = [ function() {}, { x:15, y:20 }, null, stub, "function" ]; jQuery.each( Beginner, function( i ) { var isFunc = jQuery.isFunction( Beginner[ i ]); $( "span" ).eq( i ).text( isFunc ); }); </ script > </ body > </ html > |
Output:
Contact Us