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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T08:51:52+00:00 2026-06-10T08:51:52+00:00

I have a dozen collapsible list (like the following) and each gets a bunch

  • 0

I have a dozen collapsible list (like the following) and each gets a bunch of dynamically created ‘li’s:

  <div data-role="collapsible" data-collapsed="true" data-theme="b" data-content-theme="b">
    <h3>Community Alerts
    <span id="comm_count" class="ui-li-count" style="float:right;">0</span></h3>
    <ul id="communityAlertList" data-role="listview"></ul>
  </div>

When a user does a taphold on one of the ‘li’s I want to delete it the ‘li’ (that parts working) and then I need to update/reduce the ui-li-count. To find the span and get its content I’m using the following:

    var ui_li_count = $(this).closest('span')
    var count = $(ui_li_count).textContent;    // also tried innerHTML
    alert("Count = " +count);
    count--;
    $(ui_li_count).html(count);

The alert shows “Count = undefined”.

How do I find and retrieve the textContent?

  • 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-10T08:51:54+00:00Added an answer on June 10, 2026 at 8:51 am

    The problem is your use of .closest(). The way .closest() works is to find the closest parent/child, fanning out away from the (this) element. In your code there is no span element that is a direct parent/child of an <li>, so it returns undefined.

    To put it simply using jquery selectors, the span you want to get is nested like so from your li:

    var count =  $(this).parent().parent().children('h3').children('span').text();
    

    However we don’t really want to use all those selectors, so we could just do this:

    var count =  $(this).closest('div').find('span.ui-li-count').text();
    

    Because the h3 is on the same level as your ul, we first need to get it’s container which in your example is a div. Then we use find, to find the span within that div.

    Also note that i used .text() to get the content. This is the jQuery alternative to javascripts .textContent.

    Made a simple test case so you can see it working with your code:

    http://jsbin.com/odamac/3/edit

    Hopefully this will point you in the right direction 🙂


    UPDATE

    One more problem your going to run into is that your DOM is not exactly laid out how you think it is. jQuery Mobile inserts extra elements into the page when the window loads so that it can implement it’s functionality.

    Your actual page DOM looks something like this:

    <div data-role="page">
    
        <div data-role="collapsible" class="ui-collapsible">
    
            <h3 class="ui-collapsible-heading">
                <a href="#" class="ui-collapsible-heading-toggle ui-btn">
                    <span class="ui-btn-inner">
                        <span class="ui-btn-text">
                            Community Alerts
                            <span id="comm_count" class="ui-li-count" style="float:right;">5</span>
                            <span class="ui-collapsible-heading-status"> click to expand contents</span>
                        </span>
    
                        <span class="ui-icon">&nbsp;</span>
                     </span>
                 </a>
             </h3>
    
             <div class="ui-collapsible-content">
    
                 <ul id="communityAlertList" data-role="listview" class="ui-listview">
                     <li data-theme="b" id="1" class="ui-li">1</li>
                     <li data-theme="b" id="2" class="ui-li">2</li>
                     <li data-theme="b" id="3" class="ui-li">3</li>
                     <li data-theme="b" id="4" class="ui-li">4</li>
                     <li data-theme="b" id="5" class="ui-li">5</li>
                 </ul>
    
             </div>
         </div>
    
     </div>
    

    Notice the extra and elements that jQuery Mobile has inserted to make the collapisible functionality work. You will need to account for these elements when traversing the DOM using closest();, find();, parent();, children();, etc.

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

Sidebar

Related Questions

I have couple of dozen pieces of data that I need to save and
I have created a dozen different charts using the chart form wizard in Access
I have a dozen methods in my project (C# 2.0) that look like this:
I have several dozen objects exposed through COM interfaces, each of which with many
probably a simple one, have a dozen textboxes that each contain one character. i'm
I am trying to achieve the following. I have a dozen divs with something
I have a dozen projects in the repository. The repository structure looks like below:
I have several dozen objects with an image and a share button on a
I have a dozen configuration properties files for the ant script. These files are
Ok I am new to app development I have tried dozen of codes and

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.