mercredi 15 juin 2016

Add classes to parent nodes (<a>) in a nested list

The <a> inside the last <li> of the innermost <ul> has a class which is named current. It highlights the active link.

I want to highlight all links that are parents from this link.

HTML

<ul>
    <li>
        <a href="a.html">Samsung</a>
        <ul>
            <li>
                <a href="b.html">Galaxy</a>
                <ul>
                    <li>
                        <a href="c.html">Galaxy Note 4</a>
                    </li>
                    <li>
                        <a href="c.html" class="current">Galaxy S 5</a>
                    </li>
                </ul>
            </li>
        </ul>
    </li>
</ul>

Galaxy S 5 has the class current, but I also want to add the class current to the parent links (Samsung, Galaxy).

Aucun commentaire:

Enregistrer un commentaire