Wrap nested list elements inside a Div

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Ahmed Na
    New Member
    • Jan 2014
    • 7

    Wrap nested list elements inside a Div

    I have a dynamic link generated from a database i'm trying to wrap every 9 links ( or any N number) inside a container using javaScript, the problem is it counts the children too.

    My code locks like this ( a list of nested items) :
    Code:
    <ul>
    <li>Item A
         <ul>
              <li>Item A1</li>
              <li>Item A2</li>
              <li>Item A3</li>
              <li>Item A4</li>
         </ul>
    </li>
    <li>Item B</li>
    <li>Item C</li>
    <li>Item D</li>
    <li>Item E</li>
    <li>Item F</li>
         <ul>
              <li>Item F1</li>
              <li>Item F2</li>
              <li>Item F3</li>
         </ul>
    </li>
    <li>Item G</li>
    <li>Item H</li>
    </ul>
    And i need it to count the main (li) not counts the children too, Every example I found uses a simple list instead of a nested list so their examples don't work.

    Any ideas?
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    i'm trying to wrap every 9 links ( or any N number) inside a container using javaScript
    you are aware that <li>s may only be wrapped in <ul> or <ol> tags?

    Comment

    • Ahmed Na
      New Member
      • Jan 2014
      • 7

      #3
      Yes, sorry maybe i couldn't be clear, I need it to be like this code so it will wrapped inside a Div with ul inside it as an example :

      Code:
      [B]<div class="wrapper">
         <ul>[/B]
             <li>Item A
               <ul>
                <li>Item A1</li>
                <li>Item A2</li>
                <li>Item A3</li>
                <li>Item A4</li>
             </ul>
            </li>
            <li>Item B</li>
            <li>Item C</li>
            <li>Item D</li>  
       [B]  </ul>
      </div>[/B]
      
      [B]<div class="wrapper">
         <ul>[/B]
               <li>Item E</li>
               <li>Item F</li>
                   <ul>
                      <li>Item F1</li>
                      <li>Item F2</li>
                      <li>Item F3</li>
                   </ul>
              </li>
              <li>Item G</li>
        [B]      <li>Item H</li>
         </ul>
      </div>[/B]
      Thanks

      Comment

      • Dormilich
        Recognized Expert Expert
        • Aug 2008
        • 8694

        #4
        essentially, I’d give the top <ul> a class or ID and then use document.queryS electorAll("ul# id > li") to get a reference to the first level <li>.

        Comment

        Working...