Skip to content Skip to sidebar Skip to footer

How To Find The Deepest Ul/ol With List Items In A Nested List

I am trying to clean up bulleted lists generated by another program which has created nested lists which are unnecessary. I need to remove them. Here are 2 examples... I need to f

Solution 1:

Try this:

    $('ul,ol').not(':has(ul,ol)')

$('ul,ol').not(':has(ul,ol)').each((index,list) =>console.log(list));
<scriptsrc="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script><ul><ul><li><ul><li>List Item 1</li><li>List Item 2</li></ul></li></ul></ul><ul><li><ul><li><ul><li><ol><li>Another LI 1</li><li>Another LI 2</li><li>Another LI 3</li></ol></li></ul></li></ul></li></ul>

Post a Comment for "How To Find The Deepest Ul/ol With List Items In A Nested List"