Tags

To check if the javascript function is exist, we can check using typeof(). See example below:


jQuery(document).ready(function() {
	if(typeof $(".change-password").fancybox == 'function')  {
		$('.change-password').fancybox({
			'width' : '60%',
			'height' : 400,
			'transitionIn' : 'fade',
			'autoScale' : false,
			'transitionOut' : 'fade',
			'scrolling' : 'no',
			'type' : 'iframe',
			'href' : $(this).attr('href')
		});
	}
});

// checking the jQuery blockUI plugin
if(jQuery().blockUI) {
console.log('it wont work!!');
}

if ($.fn.blockUI) {
console.log('it wont work!!');
}


if(typeof $.fn.blockUI == 'function')  {
console.log('it wont work!!');
}

if($.fn.blockUI != 'undefined') {
console.log('YES it work!!'); // recommended way to check the plugin
}
Advertisements