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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T00:41:28+00:00 2026-05-27T00:41:28+00:00

I have some htmls, where some tags does not have any children, and I

  • 0

I have some htmls, where some tags does not have any children, and I want to identify them and count the number of those tags.

I have tried the following and it doesn’t seem to work:

var count = 0;
$("th[class=gridlabel]").each(function(){
if($("th[class=gridlabel]").children().length<1)
 {
count++;
 }
});
return count;
alert(count);

not sure what’s the issue here.


I have added some additional scripts from the html source code, I want to ensure the “count” will only count the first two tags, for “answer 3” and “answer 4”, as their tags do not have children:

  <tr>
    <th class="gridlabel">answer 3</th>
    <td headers="q12_header1" class="gridcell"><input><div><span>answer 3</span><label>1</label></div></td>
    <td headers="q12_header2" class="gridcell"><input><div><label></label></div></td>
  </tr>
  <tr>
    <th class="gridlabel">answer 4</th>
    <td headers="q12_header1" class="gridcell"><input><div><span>answer 4</span><label>1</label></div></td>
    <td headers="q12_header2" class="gridcell"><input><div><label></label></div></td>
  </tr>
  <tr>
    <th class="gridlabel">other specify 1<input><label>other specify 1</label></th>
    <td><input><div><span>other specify 1</span><label>1</label></div></td>
    <td><input><div><label>2</label></div></td>
  </tr>
  • 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-05-27T00:41:29+00:00Added an answer on May 27, 2026 at 12:41 am
    var count = $("th.gridlabel:empty").length;
    return count;
    

    Update

    Given the HTML you provided, you could use something like this if you know that “non-empty” cells will have an input child :

    var count = $('th:not(:has(input))').length;
    

    If you want something a little more flexible, but a little longer, you can do something like :

    var count = 0;
    $('th').each(function(){
        if($(this).children().length < 1)
        {
            count++;
        }
    })
    

    That way you’ll cover any possible child tag. It really depends on what you need.

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

Sidebar

Related Questions

I have some data enclosed in HTML tags. I want to insert this data
I have some html files with their own css. I want to use them
I want to replace some HTML tags that I have in a CDATA element,
I have some html files that I want to convert to text. I have
I have some html extracted to a string var, and want to then use
I want to scrape some html pages that have nested form elements with lxml.
So i have some html: <a class='clicktext'>...read more!</a> and i want to give it
I have some users that can have many posts , and each of those
I have an idea to write a note-taking app in Java that does some
I tried a few simple jQuery manipulation on <button> tags but, for some reasons,

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.