What I am attempting to do is see if a jQuery object (or even DOM element for that matter) contains a particular class using the same selectors as the Sizzle engine.
jQuery publicly exposes Sizzle with the following:
jQuery.find = Sizzle;
jQuery.expr = Sizzle.selectors;
jQuery.expr[":"] = jQuery.expr.filters;
jQuery.unique = Sizzle.uniqueSort;
I can successfully use the find method to determine that a particular DOM element has a class matching my selector but I cannot seem to find a way to get access to the name of the selector that matched.
EXAMPLE (NOT WORKING AS INTENDED)
$.fn.extend({
getMatchingClass: function(selector) {
return this.each(function() {
var match = jQuery.find.matches('*[class'+selector+']', [this]);
// I would like to return the matching class's FULL NAME,
// i.e. lightbox_RESTOFCLASS
alert(match[0]);
});
}
});
var class = $('#lightbox').getMatchingClass('^="lightbox_"');
Is it possible to use Sizzle to return the class name which matched my selector?