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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T22:50:11+00:00 2026-06-06T22:50:11+00:00

In the below shown html i have this main div as cxfeeditem feeditem and

  • 0

In the below shown html i have this main div as cxfeeditem feeditem and there are many divs with the same class names and structure.My question is for all the divs starting with the class name cxfeeditem feeditem ,how to get values for the children,

1.with class name cxfeeditem feeditem

2.class=feeditemtimestamp

3.cxcomments feeditemcomments

4.cxfeeditem feeditem

 <div class="cxfeeditem feeditem">
   <span class="feeditemtext cxfeeditemtext">
      This is my blog
   </span>
   <a class="feeditemtimestamp">Yesterday 2:13PM</a>
   <div class="cxcomments feeditemcomments"> 
     These are my comments
   </div>
   <div class="cxfeeditem1 feeditem1">
     My comments for the comment
   </div>  

</div>

EDIT: Output i want to alert the values like:

    This is my blog
    Yesterday 2:13PM
    These are my comments
    My comments for the comment

I tried the following but it returns null:

$("div.cxfeeditem.feeditem").each(function() {
   alert($(this).children('span.feeditemtext.cxfeeditemtext').html());
   alert($(this).children('a.feeditemtimestamp').html());
   alert($(this).children('div.cxcomments.feeditemcomments').html());
   alert($(this).children('div.cxfeeditem.feeditem').html());
   break;
 });
  • 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-06T22:50:12+00:00Added an answer on June 6, 2026 at 10:50 pm

    The easiest way I could see is:

    ​$('.cxfeeditem.feeditem').filter(
        function(){
            return !$(this)
                .parents('.cxfeeditem.feeditem')
                .length​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​;
        }).children().each(
            function(){
                console.log($(this).text().trim());
            });​
    

    JS Fiddle demo.

    The filter() is used to ensure we’re not accessing the elements of the same .cxfeeditem and .feeditem classes that are children of the outer-most element of those classes. This feels a little messy, but given your desired output it seemed the best way.

    After that we’re simply logging the white-space trim()-ed text() of each of the (direct) child elements that haven’t been filtered-out.


    Edited in response to question from the OP in comments, below:

    What if I want to add a children class name and I do not want to consider all tags; for example if I wanted the value of only a.feeditemtimestamp and span.feeditemtext.cxfeeditemtext

    In that case you can either use a second call to filter():

    $('.cxfeeditem.feeditem').filter(
        function() {
            return !$(this).parents('.cxfeeditem.feeditem').length;
        }).children().filter(
            function() {
                var that = $(this);
                return that.is('span.feeditemtext.cxfeeditemtext, a.feeditemtimestamp');
            }).each(        
                function() {
                    console.log($(this).text().trim());
                });​
    

    JS Fiddle demo.

    Or you can use find() (and omit children()):

    $('.cxfeeditem.feeditem').filter(
        function() {
            return !$(this).parents('.cxfeeditem.feeditem').length;
        }).find('> span.feeditemtext.cxfeeditemtext, > a.feeditemtimestamp').each( 
            function() {
                console.log($(this).text().trim());
            });​
    

    JS Fiddle demo.

    References:

    • jQuery:
      • children().
      • each().
      • filter().
      • find().
      • parents().
      • text().
    • ‘Plain’ JavaScript:
      • length.
      • trim().
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Basicily i have a index.html shown below.. <html> <head> <title>UI Test: Main Menu</title> <script
I have an HTML image element as shown below: var actionImage = $(<img></img>); actionImage.attr(id,
I have a classifieds website, and in the index.html there is a form. This
I have some html which displays data from my database. Shown below is a
Given the following html table and script shown below I am having a problem
I wrote HTML to create the content shown in the image below on Safari
I have a table as shown below Q_ID DeptID EmployeeName City 100 100 testest
I have a ListView (shown below). I would like the cells to flash a
I have some code as shown below: - (IBAction)startButtonPressed:(id)sender { statusText.text = @Processing...; //here
I have added a show more or less function to a div - this

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.