473,395 Members | 1,577 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

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) :
Expand|Select|Wrap|Line Numbers
  1. <ul>
  2. <li>Item A
  3.      <ul>
  4.           <li>Item A1</li>
  5.           <li>Item A2</li>
  6.           <li>Item A3</li>
  7.           <li>Item A4</li>
  8.      </ul>
  9. </li>
  10. <li>Item B</li>
  11. <li>Item C</li>
  12. <li>Item D</li>
  13. <li>Item E</li>
  14. <li>Item F</li>
  15.      <ul>
  16.           <li>Item F1</li>
  17.           <li>Item F2</li>
  18.           <li>Item F3</li>
  19.      </ul>
  20. </li>
  21. <li>Item G</li>
  22. <li>Item H</li>
  23. </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?
Jan 29 '14 #1
3 1645
Dormilich
8,658 Expert Mod 8TB
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?
Jan 29 '14 #2
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 :

Expand|Select|Wrap|Line Numbers
  1.  
  2. <div class="wrapper">
  3.    <ul>
  4.        <li>Item A
  5.          <ul>
  6.           <li>Item A1</li>
  7.           <li>Item A2</li>
  8.           <li>Item A3</li>
  9.           <li>Item A4</li>
  10.        </ul>
  11.       </li>
  12.       <li>Item B</li>
  13.       <li>Item C</li>
  14.       <li>Item D</li>  
  15.    </ul>
  16. </div>
  17.  
  18. <div class="wrapper">
  19.    <ul>
  20.          <li>Item E</li>
  21.          <li>Item F</li>
  22.              <ul>
  23.                 <li>Item F1</li>
  24.                 <li>Item F2</li>
  25.                 <li>Item F3</li>
  26.              </ul>
  27.         </li>
  28.         <li>Item G</li>
  29.         <li>Item H</li>
  30.    </ul>
  31. </div>
  32.  
  33.  
Thanks
Jan 29 '14 #3
Dormilich
8,658 Expert Mod 8TB
essentially, I’d give the top <ul> a class or ID and then use document.querySelectorAll("ul#id > li") to get a reference to the first level <li>.
Jan 29 '14 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Brett | last post by:
I am trying to pass the value of a nested list into a function (to my "if" statement) as follows: textfilelist = "]] def idfer(listlength, comparelistlength, list): while x < (listlength - 1):...
4
by: Lee K. Seitz | last post by:
I'm still relatively new to stylesheets. I'm trying to do something that seemed fairly simple on the surface, but is proving to be a challenge. I have a set of nested lists: <ul> <li>Side...
3
by: yawnmoth | last post by:
I'm trying to center list elements in a webpage I'm working on, and setting margin-left to auto for ol (or ul) seems to prevent the number (or bullet) from displaying in IE6 (strict mode) and...
11
by: mlf | last post by:
Is there a clever way, or any way for that matter, to have a nested list show 1.1, 1.2, 1.3...2.1, 2.2, etc?
2
by: Falc2199 | last post by:
i all, I have an HTML table within which I have a span. When the user clicks a button I want to update the contents of this span with form elements table elements (TR,TD). The problem is that...
2
by: alexandre_irrthum | last post by:
Hello, I'd like to apply a function to elements of a nested list and wondered if there is anything more idiomatic and/or shorter than this recursive way: >>> def recur_map(f, data): .... if...
2
by: Juliano.net | last post by:
How can I get a list of elements inside a tag and when I find one element of a type that I choose I can change its ID and CLASS attribute? Ex: <div id="content"> <!-- I want to get the list of...
6
by: deko | last post by:
How do I construct an XHTML-compliant nested unordered list? This displays correctly (both FF and IE): <ul> <li>list item</li> <li>list item</li> <li>list item</li> <ul> <li>nested list...
2
by: Gentr1 | last post by:
Hi everybody! I am presently working on a Genetic Programming API in python. I have a bit of a problem at the moment... For some specific reasons, I am using nested lists data structure to...
3
by: suneelkn | last post by:
Unable to identify the same level for nested lists in all scenarios, when the nested-list inside an ordered list the conversion process executes with out proper list order for nested list items. The...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.