"Emphasizing the Html.ActionLink menu for improved user navigation and

Currently, I am facing an issue with my menu. I want to clear previously visited links while keeping the current one styled as a:visited in CSS.

Although I have attempted to achieve this, unfortunately, the code is not functioning properly. Here is what I have so far:

< ul id="menuTop">
  < li id="menu-link-1">
    @Html.ActionLink("Home", "Index", null, null, new { id = "link-1-visited" })
  </li>
  < li id="menu-link-2">
    @Html.ActionLink("Products", "Products", null, null, new { id = "link-2-visited" })
  </li>

  < li id="menu-link-3">
    @Html.ActionLink("Contact Us", "ContactUs", null, null, new { id = "link-3-visited" })
  </li>

  < li id="menu-link-4">
    @Html.ActionLink("About Us", "AboutUs", null, null, new { id = "link-4-visited" })
  </li>
< /ul>

Here is the JavaScript code that should make the buttons "visited":

$(document).ready(function() {
    $('#link-1-visited').click(function() {
        $("#menu-link-1").removeAttr("menu-link-1");
        $(this).addClass('link-1-visited');
        window.alert("test 1 !!");
    });

    // Code for other links...

});

And here is the relevant CSS:

ul#menuTop li#menu-link-1 a {
    background-image: url("../Content/images/Menu/menu-image-1-alt.png");
    margin-right: 1px;
}

// More CSS styles...

.link-1-visited {
    padding: 40px 20px 20px;
    border-width: 3px;
    border-bottom: 0px;
    border-style: solid;
    // more styles below...
}

// More general CSS styles...

The issue lies with the code for menu-link-1. It is not working as expected. Ideally, I would like to remove the ul and li CSS and instead add the class "link-1-visited" to it.

If you have any suggestions on how I can accomplish this, please let me know!

Answer №1

$("#menu-link-1").removeClass("active");

What is the intention behind this snippet of code? It seems like you are attempting to remove an attribute called "menu-link-1", but actually "menu-link-1" is an id and not an attribute of the li element. If you want to add or remove classes, it's best to use the class attribute instead.

Answer №2

Give this a try... (replace this with e.currentTarget and include e as a parameter in the function function(e))

$(document).ready(function() {
  $('#link-1-visited').click(function(e)
  {
    $("#menu-link-1").removeAttr("id","menu-link-1");
    $(e.currentTarget).addClass('link-1-visited');
    window.alert("test 1 !!");
  });

  $('#link-2-visited').click(function(e)
  {
    $(e.currentTarget).addClass('link-1-visited');
    window.alert("test 2 !!");
  });

  $('#link-3-visited').click(function(e)
  {
    $(e.currentTarget).addClass('link-1-visited');
    window.alert("test 3 !!");
  });

  $('#link-4-visited').click(function(e)
  {
    $(e.currentTarget).addClass('link-1-visited');
    window.alert("test 4 !!");
  });
});

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

Embed schema information into HTML tags using JavaScript

Is there a way to insert text, specifically schema data, into an HTML div tag using JavaScript? While I know how to modify existing values within a tag like class, href, and title, I am struggling to find a method to add something entirely new. Essentiall ...

css overflowing content can disrupt the layout of the screen

I am currently working on creating a modal that will be displayed in the center of the screen with the same width as the main page. However, I am facing an issue where the modal is not perfectly centered. I suspect that this is due to the overflow style ...

The stylesheet displays correctly in Grover debug mode, but does not appear in the downloaded PDF file

Having some trouble applying CSS to Grover, a tool I'm using to render and download PDF copies of documents generated in my app. While the CSS renders as expected in Grover's debug mode (rendered in Chromium), it seems that my application.css is ...

Enhancing the Appearance of HTML Select Dropdowns in JavaFX 2.2 WebEngine

I am currently working on a project that is unable to be updated to Java 1.8 to support the latest JavaFX version. While this may or may not impact the issue I am facing, I have been exploring various solutions from the internet to customize the look and f ...

Retrieve webpage using HTML stored in web storage

I am exploring a new idea for an application that utilizes local storage, and I am seeking guidance on the most effective way to load content after it has been stored. The basic concept of the app involves pre-fetching content, storing it locally, and the ...

Is it possible to incorporate an editable text feature within react-moveable? (Allowing for both dragging and editing capabilities)

In React Movable box, the text can be dragged with a left click and edited with a right click using the "contentEditable" attribute. However, on smartphones, editing seems to be disabled and only dragging is possible. <div className="move ...

Retrieving a specific object from a subarray using MongoDB's ID

My MongoDB document includes the following: const Categories = [ { _id: 's654fs54s6d4f' title: 'category 1', SubCats: [ { _id: 'jhgfsf68746' name: 'subcat 1', i ...

jQuery is attempting to create an animation by combining three variables to determine a new height

Currently, I am facing an issue with animating a div to a new height by summing up the heights of 3 other divs. Unfortunately, the heights do not seem to add up correctly, and I could really use some guidance on how to resolve this. Any suggestions or in ...

Why is my JavaScript method not working and throwing an error?

Attempting to streamline my code by creating a separate method for calling an ajax function in multiple places. When I try to use the separate method instead of calling it directly, it doesn't work as expected. data: columns[5], type: 'a ...

What is the best way to implement JQuery Ajax in order to invoke a PHP file on the server side, which will then execute returned javascripts?

I am currently working on a client website that requires a cross-domain JQuery Ajax call to a PHP file on my server. The purpose of this call is to query the database for various stored JavaScripts, which will then be returned to the client and executed on ...

What is the best way to implement the addMore event in my custom slot components when working with Vue Formulate?

I need help customizing the 'add more' button for group repeatable fields in Vue Formulate. I have created a custom slot component that is functioning correctly, but I am struggling to determine the click event needed to add another field when th ...

Changing the string "2012-04-10T15:57:51.013" into a Date object using JavaScript

Is there a way to transform the format "2012-04-10T15:57:51.013" into a Date javascript object using either Jquery or plain Javascript? ...

Integrating a form test with an XHR request following the resizing of an image for upload

I am currently facing an issue where I need to send both form input text and a client-side resized image to a php page. The image upload works fine, however, the text data appending seems to be causing problems. var xhr = new XMLHttpRequest(); xhr.onr ...

Navigate to the top of the page using Vue Router when moving to a new

Currently, in my Vue application, whenever I click on a <router-link>, it directs me to the new page but at the same scroll position as the previous one. This happens because the link only replaces the component. I am curious to know if there is a s ...

Utilizing HTML5 audio elements with jQuery enhances the auditory experience

As I delve into creating a simple media section for a website, I have encountered some challenges that I would like to address. Let me explain the issue I am facing. I currently have a 'play list' consisting of 'links' - represented by ...

When inserting the HTML of a webpage into an iframe, the displayed content may vary slightly from the original page

I am facing an issue with my webpage where I extract the html, transmit it via websockets using socket.io to another page containing an empty iframe, and then inject the html dynamically into the iframe. My code for injecting the html looks like this: fr ...

Converting bullet point list to checkboxes once requirements have been satisfied

I am working on developing a password validator with specific regex conditions in Material UI that transitions from bullet points to checkboxes when the criteria are satisfied. https://i.sstatic.net/b0pgb.png Initially, I attempted to use the npm library ...

React Select streamlines dropdown options for multi-selection by abbreviating names

Is there a way to shorten dropdown names when selected similar to the example shown in the image below https://i.sstatic.net/qUFP6.png This is the snippet of my code : multiValue: [ { value: "BUF", label: "BUF" }, ...

Exploring the world of JMeter: capturing sessions with JavaScript and jQuery

I need to capture a user session in order to conduct a performance test. I have been using the JMeter HTTP(S) Test Script Recorder, but unfortunately it is not recognizing javascript and jquery. The error message I'm receiving is: JQuery is not def ...

Using Paper.js to access and manipulate document.body.style.opacity within a paperscript

My website is essentially one large canvas image. Currently, the body fades in when loaded using this code: <body onLoad="document.body.style.opacity='1'"> However, I want to initiate this fade within my paperscript because sometimes the ...