Christoph Kammerer
Christoph Kammerer

Reputation: 21

Count how many sections in a article

At least i want to count how many sections are in one article. If this doesn´t work with this elements, I also could use normal "div" tags instead. Sorry for my bad english.

<article>
    <section>
        <p>text</p>
    </section>
    <section>
        <p>example</p>
    </section>
</article>

Upvotes: 1

Views: 1526

Answers (3)

charlietfl
charlietfl

Reputation: 171679

If you have more than one <article> and are wanting to know how many are in each one:

$('article').each(function(){
   var secCount = $(this).find('section').length;
});

Upvotes: 0

Dileep
Dileep

Reputation: 515

Try this:

     <div>
         <p></p>
         <p></p>
         <p></p>
         <p></p>
         <p></p>
     </div>

script:

     var a=$("div p").length;
     alert(a);

Upvotes: 0

Milind Anantwar
Milind Anantwar

Reputation: 82241

You can use:

$("article section").length

Upvotes: 2

Related Questions