Online Snippets Library

Check function exist before calling in jQuery

To check function exist or not we will use $.isFunction() of jQuery.

Syntax

jQuery.isFunction(obj) HTML
<!DOCTYPE html>
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"> </script>
<title>Check function exist before calling in jQuery  </title>
</head>
</html>
Javascript
$(document).ready(function(){
function myfunction()
{}
if (typeof myfunction !=='undefined'  &&  $.isFunction(myfunction) ) {
alert('myfunction exist');
}
else
{
alert('myfunction does not exist')
}
if (typeof mycheck !=='undefined' && $.isFunction(mycheck)) {
alert('mycheck exist');
}
else
{
alert('mycheck does not exist')
}
});