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

  • SEARCH
  • Home
  • 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 8337657
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T04:21:50+00:00 2026-06-09T04:21:50+00:00

What I am wanting to do is add a class to a specific element

  • 0

What I am wanting to do is add a class to a specific element with a specific url. But I can’t seem to get it to work.

This is what I have.

var pageName = window.location.pathname
    pageName = pageName.replace("/", "");

$("div.mainleftmenu a.rtsLink.rtsRoot[href=pageName]").addclass("rtsSelected");

If it helps a.rtsLink.rtsRoot is several steps into the hierarchy. I’m new to jQuery.

Update

Thanks for the quick response, but I am still getting an error.

TypeError: Object [object Object] has no method ‘addclass’ [http://XXXXXXX/training-events:69%5D

Here is a sample of the markup I am trying to traverse. (And this is auto-generated so modifying the html is not an option.)

<div class="mainleftmenu">                       
    <div id="mainleftmenu_T76A8AA8B013">
        <div id="ctl00_mainleftmenu_T76A8AA8B013_ctl00_ctl00_siteMapControl_verticalsimple"
        class="RadTabStripVertical RadTabStrip_mainleftmenu RadTabStripLeft_mainleftmenu">
            <div class="rtsLevel rtsLevel1">
                <ul class="rtsUL">
                    <li class="rtsLI rtsFirst">
                        <a class="rtsLink rtsRoot" href="products">
                            <span class="rtsOut">
                                <span class="rtsIn">
                                    <span class="rtsTxt">Products</span>
                                </span>
                            </span>
                        </a>
                    </li>
                    <li class="rtsLI">
                        <a class="rtsLink" href="products/heavybid">
                            <span class="rtsOut">
                                 <span class="rtsIn">
                                    <span class="rtsTxt">HeavyBid</span>
                                </span>
                             </span>
                         </a>
                   </li>
                </ul>
             </div>
         </div>
    </div>
 </div>
  • 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-09T04:21:51+00:00Added an answer on June 9, 2026 at 4:21 am

    You should pass the variable to the selector, currently you are passing a string:

    $("div.mainleftmenu a.rtsLink.rtsRoot[href='"+pageName+"']").addClass("rtsSelected");
    

    Also please note that you have written addclass which should be addClass.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm wanting to add some AJAX functionality to my Rails app, but have no
I have the following object: public class MyClass { public int Id { get;
I'm trying to get my theme to add CSS class names to the 'ul'
I have this weird situation. I have these two classes: Public Class Entry End
Greetings. I have an RDLC file and am wanting to add a data source
I'm wanting to add a class to the body tag without waiting for the
I have a class that contains a list of objects. I previously had this
Is it possible in C++ to have a class override a virtual function, but
I often face the problem of wanting to add additional methods to classes I
hi im wanting to know how to add google maps into a list view?

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.