Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8076989
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T15:22:50+00:00 2026-06-05T15:22:50+00:00

if i have the following links : <a href="#" onclick="return navigateTo(this)" id="menuList:0:menu" class="normalLink"> <span

  • 0

if i have the following links :

    <a href="#" onclick="return navigateTo(this)" id="menuList:0:menu" class="normalLink">
        <span id="menulist:0:menuLabel">
            <span > Main Page </span>
        </span>
    </a>        
    
    <a href="#" onclick="return navigateTo(this)" id="menuList:1:menu" class="normalLink">
        <span id="menulist:1:menuLabel">
            <span > Search Orders </span>
        </span>
    </a>
    
    <a href="#" onclick="return navigateTo(this)" id="menuList:2:menu" class="selectedLink">
        <span id="menulist:2:menuLabel">
            <span > Orders History </span>
        </span>
    </a>

I want to get the element which has the class name selectedLink and then get the value of the inner span of that element where it says in above example Order History.

I can do the first part of finding the element which has selectedLink class, but i cannot retrive the text inside the inner span of that element. Below is my code to find the element with class selectedLink:

    var elem = this.getElementsByTagName('*');
    for (var i = 0; i < elem.length; i++) 
    {
        var classes = elem[i].className;
        if(classes == 'selectedLink' ){
            alert("ok found it the selected link");
        }
    }

Can anyone suggest a way to retrieve Order History? Thanks

UPDATE: Follow up question

So the point of this excerise is that, i wanted to add a check where if the page is "Order History" yet the navigation menu had selectedLink style applied to another page (happens when user presses BACK) i wanted JavaScript logic to fix the problem so below is my code:

            //get the element that has "selectedLink" style
           // if the text says "Order History" then style is applied ok  
           var elems =  document.getElementsByClassName("selectedLink");
           if(typeof elems != "undefined"){
               for(var i = 0; i < elems.length; i++){
                   alert(elems.length);
                   var text = elems[i].innerText || elems[i].textContent;
                   alert(text);
                   if(text == "Order History"){
                       alert("its ok");
                   }
                   else { //we're here because the element that has "selectedLink" style in not "order History"
                   
                        //get all elements that have "normalLink" style and see which one is "Order History"
                       var allLinks = document.getElementsByClassName("normalLink");
                       for(var j = 0; j < allLinks.length; j++ ){
                           var curText = allLinks[j].innerText || allLinks[j].textContent;
                          
                           if(curText == "Order History"){
                               alert("there it is at counter " + j);
                               alert(allLinks[j].innerText);
                               
                               //swap the class names
                               allLinks[j].className = "selectedLink";
                               elems[i].className = "normalLink";
                               break;
                           }
                       }
                   }
                }
            }

The changing class names bit isn’t working! Am i doing it wrong?

UPDATE 2:

Fixed, It was my silly mistake :

changed the ordering of the following :

    allLinks[j].className = "selectedLink";
    elems[i].className = "normalLink";

to:

    elems[i].className = "normalLink";
    allLinks[j].className = "selectedLink";
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T15:22:51+00:00Added an answer on June 5, 2026 at 3:22 pm

    Firstly, just use getElementsByClassName() to get the element, that saves you a huge amount of effort:

    var link = document.getElementsByClassName("selectedLink")[0]; // new browsers only
    var link = document.querySelector(".selectedLink"); // more support, but not in IE7 or lower
    var link = $(".selectedLink"); // with jQuery
    

    Then, since that text is the only text, you can just use textContent (innerText in older IE)

    Your end code is one of these, depending on your target browsers and if you have a framework or not:

    var text = link.textContent; // new browsers
    var text = link.innerText || link.textContent; // older browers
    var text = link.text(); // jQuery
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following code which works great:- $('.ajax a').click(function() { getpageajax(this.href); return false;
I have links like following. <a href=/Customer/_EditCustomer?CustomerId=2 class=customer_details>Deneme Müşteri 2</a> <a href=/Customer/_EditCustomer?CustomerId=3 class=customer_details>Deneme Müşteri
I have the following links at the top of my web page: <ul class=icyLink>
I have the following two links in my main menu, and I have some
I have the following HTML with many of these kinds of links: <a class=button
I have the following HTML: <ul class=vertical_menu no_select> <li class=edge_top>&nbsp;</li> <!-- Menu Items Here
I have the following goal: I Have a list of top menu links on
I have a set of links: <a href='#?idCountry= + MX + ' class='SendData'>Mexico</a> <a
I have the following regex expression to match html links: <a\s*href=['|](http:\/\/(.*?)\S['|]> it kind of
I have the following links in a sql dump file(.sql). I need to use

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.