JQuery | isFunction() method
Last Updated :
27 Apr, 2020
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 >
</ head >
< body style = "text-align:center;" >
< h1 style = "color: green" >
GeeksForGeeks
</ 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 >
</ head >
< body style = "text-align:center;" >
< h1 style = "color: green" >
GeeksForGeeks
</ h1 >
< h3 >JQuery | isFunction () method</ h3 >
< b >Check the following are the function or not. </ b >
< br >< br >
< div >jQuery.isFunction( geeks[ 0 ] ) = < span ></ span ></ div >
< div >jQuery.isFunction( geeks[ 1 ] ) = < span ></ span ></ div >
< div >jQuery.isFunction( geeks[ 2 ] ) = < span ></ span ></ div >
< script >
function stub() {}
var geeks = [
function() {},
{ x:15, y:20 },
null,
stub,
"function"
];
jQuery.each( geeks, function( i ) {
var isFunc = jQuery.isFunction( geeks[ i ]);
$( "span" ).eq( i ).text( isFunc );
});
</ script >
</ body >
</ html >
|
Output:
Share your thoughts in the comments
Please Login to comment...