Avatar of MJ
MJFlag 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>
    </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>
    </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>
    </div>
</div>

Open in new window

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

User generated image



JavaScriptjQueryHTMLWeb Development

Avatar of undefined
Last Comment
leakim971
ASKER CERTIFIED SOLUTION
Avatar of leakim971
leakim971
Flag of Guadeloupe image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
JavaScript
JavaScript

JavaScript is a dynamic, object-based language commonly used for client-side scripting in web browsers. Recently, server side JavaScript frameworks have also emerged. JavaScript runs on nearly every operating system and in almost every mainstream web browser.

127K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo