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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T14:04:12+00:00 2026-06-10T14:04:12+00:00

I have to select elements which contains id attribute and class attribute having ‘child-of-‘

  • 0

I have to select elements which contains id attribute and class attribute having ‘child-of-‘ value and loop through the elements returned by the selector.

So far i could write:

$('.child-of-').each(function(){
...
});

This selects all the elements having class of child-of- including elements which does not have id also.
There are elements which has that class but does not have any id attribute.
so How can i select elements which has ‘id’ attribute and id has some value and also has class of child-of-. ?

For example

 <div id="any1" class="child-of-"></div>
 <div id="any2" class="child-of-"></div>
 <div class="child-of-"></div>

Only the div having id attribute must be selected. ie the first two divs in the example. the third does not have id attribute value and hence should not be selected

  • 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-10T14:04:14+00:00Added an answer on June 10, 2026 at 2:04 pm

    You can use attribute selector.

    $('.child-of-[id]').each(function(){
        ...
    });
    

    Fiddle


    If your classes starts with child-of- you can use attribute starts with selector:

    $('[class^="child-of-"][id]').each(function(){
        ...
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a div which contains 2 child elements. The 1st div have content
I have dropdown-Lists which have a lot of elements (>1000). When I select one
How do i select elements that have my custom data attribute data-validate with jQuery
I have next problem, when I'm trying to retrieve value from xforms:select elements I
I have a listview NoteList which contains a method doListRefresh() to select list contents
I have two select elements, A and B: when A's selected option changes, B's
OK, I have two HTML select elements and a button. I need to disable
I have n number of select elements in an html page that are used
In trying to select elements that have any attributes, the following throws a jQuery
I have a form with 3 select elements. Each one, by default, has option

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.