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 6640627
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T23:41:42+00:00 2026-05-25T23:41:42+00:00

My problem is as follows: I have a simple navigation <ul class=navigation> <li class=heading

  • 0

My problem is as follows:

I have a simple navigation

<ul class="navigation">
                <li class="heading selected">Slider images</li>
                <li><a href="index.php?action=staticpages" title="">Static pages</a></li>
                <li><a href="index.php?action=accomodation" title="">Accomodation</a></li>
                <li><a href="index.php?action=general" title="">General</a></li>
                <li><a href="index.php?action=settings" title="">Settings</a></li>
                <li><a href="index.php?action=dologout" title="">Logout</a></li>
</ul>

and my “not finished” jQuery function:

$('.navigation li a').click(function(e) {
    e.preventDefault();
    $('.navigation li').removeClass('heading selected');
    $(this).parent().toggleClass('heading selected');
});

The li element with class “heading selected” is the default/selected element.

What I want to achieve after clicking on the other li element:

            <li><a href="index.php?action=sliderimages" title="">Slider images</a></li>
            <li class="heading selected">Static pages</li>

in short, remove “heading selected” list class from the default one, assing this class to the newly clicked element, also, add anchor href to the default one, and remove anchor tag from the newly clicked element.

Thanks in advance guys! 🙂

  • 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-05-25T23:41:43+00:00Added an answer on May 25, 2026 at 11:41 pm

    To make this somewhat more simple to implement, I’d suggest you don’t add/remove the a elements from the li, and simply use CSS to style the elements as ‘default text’, and JS to prevent the default behaviour.

    You can use this as a guide:

    $('.navigation li a').click(
        function(){
            if ($(this).is('.headingSelected')) {
                return false;
            }
            else {
                $(this)
                    .closest('li')
                    .siblings()
                    .removeClass('headingSelected');
                $(this).closest('li').addClass('headingSelected');
                return false;
            }
        });
    

    JS Fiddle demo.

    Note that I’ve concatenated your ‘heading selected’ class names into one single, camel-cased, ‘headingSelected’, also, in the linked demo, I had to guess what the URL of the first link should be. So be aware of that if you should try a direct copy/paste.


    Edited to address my misconception that this was used for intra-page navigation, or Ajax interaction.

    The following seems to work, but will need to be included in all pages that require the functionality (Whether in-line in the head of the document or via a linked js file):

    var currentURL = "http://www.yourwebsite.com/index.php?action=staticpages";
    var page = currentURL.substring(currentURL.indexOf('=') + 1);
    
    $('.navigation a').each(
        function(i){
            if ($(this).text().toLowerCase().replace(' ','') == page) {
                $(this).closest('li').addClass('headingSelected');
            }
        });
    

    JS Fiddle demo.

    If you should use the above, simply ensure that you remove the headingSelected class name from the html, and allow the script to assign the class when it runs.

    More concisely, but otherwise exactly the same as the previously edited answer, you could use instead:

    var currentURL = "http://www.yourwebsite.com/index.php?action=staticpages";
    var page = currentURL.substring(currentURL.indexOf('=') + 1);
    
    $('a[href$="' + page + '"]').closest('li').addClass('headingSelected');
    

    JS Fiddle demo.

    References:

    • click().
    • is().
    • closest().
    • siblings().
    • removeClass().
    • addClass().
    • substring().
    • indexOf().
    • each().
    • text().
    • toLowerCase().
    • attrubte$="value" attribute-ends-with selector.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is a weired problem, I have implemented simple quick sort as follows.. static
I have a mysql problem, my query looks as follows but not complete SELECT
I have a simple CSS problem In this site http://web.cinaird.se/pdf/test.htm (<--removed) I have a
I have got a simple HTMl form with one field as follows: <input type=text
I have a simple SAS (version 9.2) program as follows, proc model; cdf('normal',log(V/100)+1)=0.5; bounds
i have a simple oracle stored procedure proc1 as follows: CREATE OR REPLACE PROCEDURE
I have a problem with a website I'm putting together. I have a simple
The problem is as follows: I have the following XML snippet: <time format=minutes>11:60</time> The
I have a simple web app webapp static images - a.gif pages - test.html
I have a simple many-to-many relationship between the User class and the Place class.

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.