Avatar of MJ
Flag for United States of America asked on

JavaScript - How to get text of active child and Parent Elements in a Menu

Using JavaScript Only, I'm trying to get the text of the active child menu element (class=item active child) which would be "Basic Details" in the example and also the parent text which would be "Customer Information" in the example provided. Please note: the class for the parent div can be different for each menu item (e.g. "c-info" or "item c-info").

<div class="grid-col-menu">
    <div class="c-info">Customer Information</div>
    <div class="side-menu">
        <div class="side-menu-parent">
            <div class="item child"><span>Associated Individuals</span></div>
            <div class="item active child"><span>Basic Details</span></div>
            <div class="item child" hidden=""><span>Additional Information</span></div>
    <div class="side-menu-parent">
        <div class="item c-info">Individual Information</div>
        <div class="side-menu-child" hidden="">
            <div class="item child"><span>Basic Details</span></div>
            <div class="item child" hidden=""><span>Additional Information</span></div>
    <div class="item c-info">Summary</div>
    <div class="c-info" hidden="">Documents</div>
    <div class="side-menu-child" hidden="">
        <div class="item child"><span>Upload &amp; esign</span></div>

Open in new window

Please no jQuery, JavaScript only. Here is an example of the menu when different items  are selected. Thank you!

JavaScriptjQueryHTMLWeb Development

Avatar of undefined
Last Comment

8/22/2022 - Mon

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes