Showing identification on the drop-down list

Within my dropdown menu setup, I am aiming to achieve a specific functionality. When the user clicks on sub menu, I want the title of sub menu to display in the Menu space as illustrated below.

What steps can be taken to accomplish this?

UPDATE: After further consideration, it seems that my initial explanation was not clear enough.

Let's say, for instance, a user selects the Sub Menu 2 option, they will then be directed to a corresponding page.

This particular Sub Menu 2 page will have a designated url of sub_menu_2. For example, the URL of the page may be something like .com/sub_menu_2

When users navigate to the sub menu 2 page, I would like the menu title to reflect 'sub menu 2' accordingly.

I apologize for any confusion caused earlier.

Answer №1

Check out a potential fix here: https://jsfiddle.net/mboz45fv/3/

To enhance your main and sub menus, assign classes with the following values:

<h1>Drop Down Menu</h1>
<nav id="primary_nav_wrap">
<ul>

  <li><a class="main-menu" href="#">Menu</a>
    <ul>
      <li><a class="sub-menu" id="a" href="#">Sub Menu 1</a></li>
      <li><a class="sub-menu" id="d" href="#">Sub Menu 2</a></li>
      <li><a class="sub-menu" id="c" href="#">Sub Menu 3</a></li>
    </ul>
  </li> 
</ul>
</nav>

$('.sub-menu').on('click', function(){
    $('.main-menu').text($(this).text())
});

UPDATE: To revert back to the 'Menu' text when the control is not in focus, follow this method:https://jsfiddle.net/mboz45fv/9/

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Cookies are strangely absent from the ajax call to the web api - a puzzling issue indeed for Web Api users

Hello, here is the code I'm working with using Ajax: function GetCurrentUserId() { return $.ajax({ type: "GET", url: rootUrl + '/api/Common/CurrentDateAndUser', dataType: 'json', ...

Exploring the Spotify API with jQuery/ajax to fetch details about songs, artists, and albums

I've been researching and have come across some information that is somewhat similar, but I'm still struggling to completely understand how this process works. My goal is to make a request to the Spotify API using jQuery to search for an artist ...

I am experiencing difficulties with my custom font not functioning properly

I've experimented with the following code: @font-face { font-family: Jua; src: url('/fonts/jua.ttf'); } @font-face { font-family: Jua; src: url('..../fonts/jua.ttf'); } @font-face { font-family: Jua; src: url('.../fonts/jua.t ...

Challenges with displaying css/bootstrap classes within angular2

Experiencing difficulties with CSS/Bootstrap integration when displayed in an angular2 component. When attempting to display the CSS and HTML content in the Index.html file (with proper CSS and JS references), everything functions correctly. However, once ...

The submitHandler constantly refreshes the webpage

Struggling to send a form to a PHP file upon submission and retrieving the value without having to reload the page. It was working smoothly for some time but now it just won't cooperate. I have multiple pages with similar functionality, where 2 work p ...

How can I extract a substring from a URL and then save it to the clipboard?

Hi there! I'm working on a project for my school and could really use your expertise. I need help extracting a substring from a URL, like this one: URL = https://www.example.com/blah/blah&code=12432 The substring is: 12432 I also want to display ...

Retrieve the link of a nearby element

My goal is to create a userscript that has the following functionalities: Add a checkbox next to each hyperlink When the checkbox is clicked, change the state of the corresponding hyperlink to "visited" by changing its color from blue to violet. However ...

Having trouble with this code// Does anyone know how to make the div slide in line with other divs when hovering over it?

After spending countless hours analyzing and trying various solutions, I have come to the realization that I need to seek help with my code. The task at hand is proving to be incredibly frustrating, and I have exhausted all other options before resorting t ...

Load the identical page using jQuery and insert it into a specified <div> element

I have been using the load method to dynamically load content into a div, but I encountered an issue in my case. When trying to load a page that contains external JS files into the same page, the JS files get loaded twice - once when the page is initially ...

Generating an Xpath for the selected element with the help of Javascript or Jquery - here's how!

On my website, I have implemented a click event on an element. When a user clicks on this element, I want to generate the XPath of that particular element starting from either the html or body tag, also known as the Absolute Xpath. For example, if I click ...

What is the best way to align all menu items horizontally with the logo?

I'm facing a small issue that I can't seem to resolve on my own. I recently added a links menu to the header of my website, and it looks like the menu has fixed dimensions, causing the Login URL to get pushed down due to space constraints. I&apos ...

Issue with codeigniter and jquery login functionality not triggering/responding

My controller had a working login function that suddenly stopped functioning after some changes were made. The login feature consists of two input fields for username and password, along with a submit button. //Javascript function initLogin(e) { e.p ...

Tips for using various versions of jQuery at the same time

Despite searching on Stack Overflow, none of the answers provided seem to work for my issue. My requirement is to utilize two separate versions of jQuery. Below is the code snippet: I first link to the initial version and use the following code: <sc ...

What sets apart the two syntaxes for JavaScript closures?

Similar Query: Is there a distinction between (function() {…}()); and (function() {…})();? I've come across a way to prevent variables from becoming global by using the following syntax: (function ($, undefined) { })(jQuery); Rec ...

Can you explain the meaning of this compound CSS selector?

.btnBlue.btnLtBlue Is this referring to an element that has both the classes btnBlue and btnLtBlue applied? ...

Performing a validation on data fetched using a .load() function

I've been struggling with a persistent issue that I just can't seem to solve. So, here's the situation: I have a blog post on a CMS that I'm developing. The content is saved within a div with its own unique ID. When the user clicks an ...

Discover the path with the power of JavaScript

Imagine I am including a JavaScript file in this manner: <script type="text/javascript" src="http://foo.com/script.js?id=120#foo"></script> Would it be possible to access the GET or hash parameters passed through this? Currently, I achieve t ...

In IE8, submitting an Ajax request almost always results in an error being

This piece of code seems to be causing some trouble, as it works fine in all browsers except for IE8 on an XP machine. No matter what I try, the error function keeps getting triggered specifically in IE8. I've experimented with different dataTypes lik ...

Unexpected issue encountered during ajax request to an API

Struggling to make an API call with necessary data. The request successfully reaches the server. ...

using jquery to fill in fields in a table form

I am currently working with a basic html table that initially has two rows, each containing 2 form fields. Users have the ability to add more rows to the table by following this process: $('a#addRow').click(function() { $('#jTable tr:la ...