SitePoint Sponsor

User Tag List

Results 1 to 2 of 2

Hybrid View

  1. #1
    SitePoint Member
    Join Date
    Dec 2012
    Posts
    12
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question [jQuery] Overriding block tags on the number of fields in a section

    I have a code:
    Code:
    <ul id="list_people">
      <li>
        <h4>A<!-- There should add: 3 --></h4>
        <ul>
            <li>Adamski Piter</li>
            <li>Amart Jan</li>
            <li>Azyl Pawel</li>
        </ul>
        </li>
      <li>
        <h4>B<!-- There should add: 2 --></h4>
        <ul>
           <li>Bamer Anna</li>
           <li>Bit Miron</li>
        </ul>
      </li>
        <li>
        <h4>C<!-- There should add: 1 --></h4>
        <ul>
           <li>Cel Maciej</li>
        </ul>
      </li>
    </ul>
    <script type="text/javascript">
    var number_of_sections=$('#list_people h4').size();
    
    var people_in_the_section=[];  
    for(var i=0; i<number_of_sections; i++)
    {
        people_in_the_section[i]=$("#list_people li ul lil:eq(" + i + ")").size();
        $("#list_people h4:eq(" + i + ")").append(people_in_the_section[i]);
    
    }
    </script>
    My question is: what am I doing wrong that it does not show me the correct number of tags h4 searched elements?

  2. #2
    Gre aus'm Pott gold trophysilver trophybronze trophy
    Pullo's Avatar
    Join Date
    Jun 2007
    Location
    Germany
    Posts
    5,312
    Mentioned
    178 Post(s)
    Tagged
    8 Thread(s)
    Hi there,
    I don't know if this helps, but you can find the number of h4 tags within the "list_people" <ul> like this:

    Code JavaScript:
    $("#list_people h4").length;


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •