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 7804723
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T02:00:47+00:00 2026-06-02T02:00:47+00:00

Given an element like <div class=A B></div> where the classes of the div are

  • 0

Given an element like

<div class="A B"></div>

where the classes of the div are unknown and/or can change,
I want to select elements like

<div class="A"></div>
<div class="B"></div>
<div class="A B"></div>
<div class="B Foo"></div>

in other words any element which has class A or B.

jQuery has the is() function, so I thought about grabbing the string containing the classes of the main div using attr("class"), prefixing each class with . and using is() to filter, but that feels like a hack. Any way to do this elegantly?

  • 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-06-02T02:00:49+00:00Added an answer on June 2, 2026 at 2:00 am
    $('#targeted_div').click(function() {
        if (this.className) {
            var classes = $.trim(this.className).split(/\s+/);
            var matches = $('.' + classes.join(',.'));
        }
    });
    

    So if the classes for '#targeted_div' are A B, the selector for the matches will be '.A,.B'. In other words, it will select any elements that have at least one of those classes.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Normally I would create an element in jQuery like this $('<div id=errors class=red></div>') Can
Given an XML element in jQuery like so: $('<foo oy=vey foo=bar here=is another=attribute />')
Given a div such as: <div class=widget block dock clock>yada yada</div> I'd like to
Suppose I have an element like this: <div id=dv class=red green blue>Something Here !!</div>
I'm trying to select an element given by: /html/body[@id='someid']/form[@id='formid']/div[@id='someid2']/div[@id='']/div[@id='']/div[@id='']/table/tbody[@id='tableid']/tr[7]/td[2] Now the html of that
Given this element: <div class=box id=trololo> <h2 class=header gradient-red></h2> <div class=body> <div class=queue> <ul
I want to select a set of DIV elements that are contained inside a
Given a list of elements like so: int[] ia = new int[] { -4,
how can i get immediate parent of a given element ? $(e.target).parent() ?
See title. Additionally, how can I tell if a given child element is only

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.