Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 553875
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T11:39:02+00:00 2026-05-13T11:39:02+00:00

What I am attempting to do is see if a jQuery object ( or

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T11:39:03+00:00Added an answer on May 13, 2026 at 11:39 am

    I’ve come up with a non-sizzle solution using a subset of selectors (^=, $=, *=, and =) which is fully working. A Sizzle solution would have been nice, however. This should at least demonstrate what the intended functionality of the plugin should do.

    $.fn.getMatchingClass = function(selector) {
        var regex, class, tmp, $this;
        tmp = $(this)[0].className;
        class = selector;
        class = class.replace(/(\^|\*|\$)?=/i, '');
        class = class.replace(/\"/g, '');
        if (selector.indexOf('$=') != -1) {
            regex = new RegExp('[\\s]+' + class + '$', 'i');
        } else if (selector.indexOf('^=') != -1) {
            regex = new RegExp('^' + class + '[\\s]+', 'i');
        } else if (selector.indexOf('*=') != -1) {
            regex = new RegExp('[a-zA-z0-9_\\-]*' + class + '[a-zA-z0-9_\\-]*', 'gi');
        } else if (selector.indexOf('=') != -1) {
            regex = new RegExp('^' + class + '$', 'i');
        } else return false;
        return tmp.match(regex);
    }
    
    var class = $('#myID').getMatchingClass('*="lightbox"');
    var class2 = $('#myID').getMatchingClass('^=lightbox');
    var class3 = $('#myID').getMatchingClass('="lightbox"');
    var class4 = $('#myID').getMatchingClass('$=lightbox');
    alert(class);
    alert(class2);
    alert(class3);
    alert(class4);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am attempting to create a jQuery plugin for my own use that can
I'm attempting to create a simple backbone view that attaches to an <li> element.
I am attempting to handle multiple concurrent events using jQuery but I am having
Hi Im attempting to search a string to see whether it contains a email
I'm attempting to write some jquery from the first time and I'm using the
I am attempting to use jQuery easing function easeInBounce and I see this error:
So the situation is this: attempting to add a dropdown box using the jquery.multiselect
You can see my project here - http://www.inluxphoto.com/custom/jsgallery/index.php I am attempting to make the
Attempting to make a NSObject called 'Person' that will hold the login details for
I am attempting to use the jCorner plugin for jQuery, but falling down at

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.