I\'m using jQuery and have some interactions with a jQuery UI where I need to get options. However there\'s a possibility that the jQuery UI function has not been applied yet t
I prefer to use hasOwnProperty on any object in JavaScript, since it returns a boolean every time.
var hasWidget = $( "selector-here" ).data().hasOwnProperty( "widget-name-here" );
if ( hasWidget )
{
// Put your awesome code here.
}
Which IMHO is a little better than checking null; what if it switches to undefined, which, also IMO is what it should return.