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

  • Home
  • SEARCH
  • 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 7801495
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T00:58:03+00:00 2026-06-02T00:58:03+00:00

I want to only select elements that match class X and don’t have any

  • 0

I want to only select elements that match class X and don’t have any siblings that also have class X. In my case, X = hasDatepicker. Here’s what I’ve come up with:

$('.hasDatepicker:not(.hasDatepicker ~ .hasDatepicker)')

However, this does not exclude the first element, so in any group of datepickers, this will still select the first one. I don’t want to include any that are in a group, only the singles.

Example with 1 Match:

<div class="input text">
<input name="data[Goal][date_started]" type="text" value="" class="hasDatepicker" style="display: none; ">
<button type="button" class="ui-datepicker-trigger"><img src="/themed/mocha/images/btn_calendar.png" alt="..." title="..."></button>
</div>

Example with 0 Matches:

<div class="input text">
<input type="text" value="" id="GoalDateStarted" class="hasDatepicker"><input type="text" value="" class="hasDatepicker" style="display: none; ">
<input type="text" value="" class="hasDatepicker" style="display: none; ">
<input name="data[Goal][date_started]" type="text" value="" class="hasDatepicker" style="display: none; ">
<button type="button" class="ui-datepicker-trigger"><img src="/themed/mocha/images/btn_calendar.png" alt="..." title="..."></button>
</div>

Any ideas? Thanks!

  • 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-02T00:58:04+00:00Added an answer on June 2, 2026 at 12:58 am

    It is not that elegant but it does the trick using the :first-child pseudo-selector and filtering the result set with .filter():

    • :first-child will help select only the first .test element of a possible multiple siblings list

    • use .filter() to actually check if there are no siblings with the same class

    Here’s the code:

    var a = $('.test:first-child').filter(function() {
        //return $(this).parent().find('.test').not(this).length == 0;
        return !$(this).siblings('.test').length
    });
    

    DEMO

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

Sidebar

Related Questions

Let's suppose that I have a list of elements, and I want to select
I have a fairly large model and I want to retrieve only a select
this is what i want. but i have put only a specified date. SELECT
I want to select a post only if $arr_tags match all array_elements with tags_is_tags
As the title says, is it possible to select elements in XPath that only
I have some elements that when clicked will fire some action and select the
Is it possible to use XPath to select only the nodes that have a
i've got an id attribute value for an element. i want to select only
I want to select only the id which has the maximum precedence with the
Using PHP and MySQL, I want to select only 6 rows from table which

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.