hey guys, i've been pulling my hair out over this one. I need to get the class name of each link in an unordered list. I know it sounds easy enough, but it's a little more complicated than
`$('ul > li > a').attr('class');`
I have a pretty large menu of all the departments in our company. there are something like 33-34 items in the list. Each department except 3 or so has a sub department, and many of the items in each sub department have a sub department. Now I'm the only programmer here and my bosses wanted a solution where a non-programmer could add/remove items from the menu. Due to limitations with the ecommerece platform we use (easystore creator, and no i wouldn't recommend it to anyone) I can't use a database or any server side languages. So I'm using a XML file that contains all the departments, sub departments and level three departments. I then use the `$.ajax()` method to load the xml file and parse the XML data into the menu.
I'm good until I get to the part where I have to build the level three menus. I have an array that contains true/false as to if the given submenu has a level three menu in it somewhere. The position of the bool in the array plus 1 corresponds with the submenu. So if `flag = false` it means that submenu1 has no level three menu.
I went ahead and appended an unordered list with the class `level3` to each item in the submenu if it has a level three menu in it somewhere. In the XML file the node that contains the level three information is called `` and has an attribute `for` that tells which item in the submenu the level three menu goes to. The `for` attribute is formatted `deptXX.YY` where XX is the submenu it belongs to and YY is the item in the submenu it belongs to. So if it where `dept05.02` it means that submenu 05, item 02 (items start counting at 00).
This is wear the class comes in. Each link in the first sub menu, or levelTwo as I call it, has a class `levelTwoLinkXX` where XX is the order of the links. Ex. if there are 4 links in the submenu the first link is `levelTwoLink00` and the last is `leveTwoLink03`. Now what I am trying to do is fill an array with the classes of the levelTwo menu only if it has a level three menu. So far the only thing i've managed to accomplish is load all the classes for each link from every levelTwo menu into the array.
I hope I've explained everything. If there is anything I need to clear up, please let me know; and thanks in advance
Suppose levelTwoLink01 has a level three menu and levelTwoLink00 does not. I need to remove the level3 ul from that list item
Did you know that HTML is an XML derivative, just have a separate HTML file instead of a complicated XML file, and then load that with the jQuery.get().
以上就是get class name from group of links in ul的详细内容，更多请关注web前端其它相关文章！