1) You have typo in code: $_.data
instead of $._data
2) You can't use selector
argument as object property using dot .
This is string, and if you want to check that object has such property name you should use brackets obj[selector]
So fixed code for this expression will look like following:
jQuery.expr[':'].hasEvent = $.expr.createPseudo(function( selector, context ) {
return function(elem) {
return ($._data(elem, 'events') != undefined && $._data(elem, 'events')[selector] != undefined);
}
});
Working JSFiddle available here.