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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T13:32:59+00:00 2026-06-15T13:32:59+00:00

In my code below, i’m doing menus. What I’m trying to do is, when

  • 0

In my code below, i’m doing menus.

What I’m trying to do is, when a user clicks a menu item, that menu items class need to get changed to ‘current’ and the menu item with ‘current’ need to get changed to ‘menu’.

But I just cannot get things to work.

Ok… current gets changed to menu. i can tell by the color. But when I click the one that was changed from ‘current’ to ‘menu’, the alert wont appear.

Also, how do i set the menu class to current based on the data-feed name that was clicked? Can you see how this can be done?

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>PHP, jQuery search demo</title>
<style type="text/css">
.current{
padding:5px;
border:1px solid #000000;
background-color:white;
}
.menu{
padding:5px;
border:1px solid #000000;
background-color:red;
}
</style>

<script type="text/javascript" src="http://localhost/dev/ajax/jquery.js"></script>
<script type="text/javascript">
$(function() {

    $(".menunavi .menu").click(function() {

        alert ($(this).attr("data-feed"));
//Set the span with class="current" to class="menu"
        $(".menunavi .current").addClass("menu");
//Set the span with class="menu" to class="current" were data-feed = 'whatever was clicked'
        $(".menunavi .menu").addClass("current");

    });
});
</script>

</head>
<body>
        <div class="navigation clearfix">
            <div class="menunavi">
                    <span class="current" data-feed="photos">Photos</span>
                    <span class="menu" data-feed="watches">Watches</span>
                    <span class="menu" data-feed="audio">Audio</span>
                    <span class="menu" data-feed="sports">Sports</span>
                    <span class="menu" data-feed="drinks">Drinks</span>
                    <span class="menu" data-feed="furniture">Furniture</span>
                    <span class="menu" data-feed="computers">Computers</span>
                    <span class="menu" data-feed="stationary">Stationary</span>
                    <span class="menu" data-feed="phones">Phone</span>
                    <span class="menu" data-feed="cosmetics">Cosmetics</span>
            </div>
        </div>
</body>
</html>
  • 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-15T13:33:00+00:00Added an answer on June 15, 2026 at 1:33 pm
    $('.menu,.current').click(function(){
       $(this).siblings().removeClass('current').addClass('menu');
       $(this).removeClass('menu').addClass('current');    
    });​
    

    Here is a jsfiddle http://jsfiddle.net/N4Gec/2/

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

Sidebar

Related Questions

Code below defines a ChargeCustomer class that contains an array of type customers. I
Code below is working well as long as I have class ClassSameAssembly in same
The code below simply didn't work. document.getElementById('files').addEventListener('change', handleFileSelect, false); reported by firebug that this
The code below fails on the line: Class.forName(oracle.jdbc.driver.OracleDriver); with the error: java.lang.ClassNotFoundException: oracle.jdbc.driver.OracleDriver The
The code below sets a select menu with UI selectmenu by $('.anyclass').selectmenu(); but the
The code below is written in php: $user = addslashes($_POST['user']); $pwd = addslashes($_POST['pwd']); $query
Code below contains a JS function that receives as parameter String €€ (Euro sign).
Code below. The outcome of this is that each document ends up with the
Code below is pseudo code. Imagine a class Fruit which has a factory method
In below code i'm doing somthing wrong. Sorry if this is a bit basic.

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.