0

I try to create a Navigation, with less Javascript possible. Ideally without any Javascript.

So for that I want to know, how I can find out, if a LI has a child UL, with a submenu. If the li has a ul child, the li should get a class (arrow eg).

Example:

    <ul>
        <li>Some List Item</li>
        <li class="needAwayToMarkThisAsHasChildUl">Some List Item
            <ul>
                <li>Some sub list item</li>
            </ul>
        </li>
    </ul>

Is this possible without Javascript?

  • 2
    Are you just trying to target the li with CSS? If so you can use "ul li ul li" – dustytrash Sep 08 '18 at 22:43
  • you do not need to add a class nor a parent selector. https://codepen.io/gc-nomade/pen/gdoayE – G-Cyrillus Sep 08 '18 at 23:02
  • @Termanafif .. a bit fast to close a question as a duplicate when a parent selector is not needed . beginners need to be shown otherwise and learn to use structure and css side by side. What he wants can be done without js nor a parent selector. https://codepen.io/gc-nomade/pen/gdoayE The answer to the question is: yes without even a class – G-Cyrillus Sep 08 '18 at 23:05
  • @G-Cyr well, the arrow was an example ... and the question for me is "how can I add a class to an element that contains a specific child" : and this is impossible with CSS, even if we have the parent selector we cannot add class with CSS (we can only apply style) ... If the OP can change the question to be more precise and have a particular case where indeed we don't need any complex stuffs then we can reopen the question. – Temani Afif Sep 08 '18 at 23:11
  • I understood why you closed it, i also think a beginner hardly make clear question just because there is so much they do not know or think about yet. He will stick to the idea he is in needs of a parent selector , but you and i know, we do rarely need this ;) the case here is to apply an arrow when an li contains an ul – G-Cyrillus Sep 08 '18 at 23:27

0 Answers0