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

The Archive Base Latest Questions

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

Here I have html structure. It repeats several times on the page. <article class=boo>

  • 0

Here I have html structure. It repeats several times on the page.

<article class="boo">
    <h4>Here goes the title</h4>
</arcticle>

I want to count the number of characters in each header h4 inside of article.

$('article.boo h4').text().length > 70

Counts the total number of characters in all headers. What I want is to check if each and every of the headers is longer than 70 characters.

What is the best way to loop through all the elements and make a validation in this case?

Thank you

  • 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-28T00:21:06+00:00Added an answer on May 28, 2026 at 12:21 am

    You could use jQuery’s each() method, i.e:

    $('article.boo h4').each(function() {
        if ($(this).text().length > 70) {
           //do stuff if longer than 70 chars
        }
    });
    

    Or, depending on your definition of ‘best’, you could use a standard JavaScript for loop:

    for (var x = 0, y = $('article.boo h4').length - 1; x < y; x++) }
        if ($('article.boo h4')[x].text().length > 70) {
            //do stuff if longer than 70 chars
        }
    }
    

    If your definition of best means ‘easiest’ the first option may be the way to go, if by best you mean ‘most performant’ use the second, although if necessary that could be improved with selector caching so as not to select an element on each loop iteration

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

Sidebar

Related Questions

I have the following html snippet: <a href=page1.aspx class=title>page title goes here</a><br /> <span
I have some content sliding here. http://www.smallsharptools.com/downloads/jQuery/Slider/slider.html The HTML structure is simple. There is
I have html like so: <div class=foo> (<a href=forum.example.com>forum</a>) <p> Some html here.... </div>
I have this html code that i want to edit with jQuery. Here is
Here's the problem: 1.) We have page here... www.blah.com/mypage.html 2.) That page requests a
I have one html structure: enter code here <ul> <li><span>aaa</span> <div> <ul> <li><span>bbb</span> </li>
I have a html structure like this: <div class=one> <div id=two> <h2>Any</h2> <h4>Any</h4> </div>
I have this kind of HTML structure (stripped down for easy readability): <head> <title>My
Suppose I have this HTML structure: <div class=a> <div class=floated-left>...</div> <div class=floated-left>...</div> </div> I
I have the following html structure: <div class=decorator> <div class=EC_MyICHP_Item> <div class=text> <h3><a target=_blank

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.