To access a different page, simply click the link and update the class on the new page

I am facing an issue with the tabs on my homepage. Currently, only one tab with the "current" class is visible while the rest are hidden.

Is there a way to link from pageX to my homepage and specify which tab should be open?

For instance, when clicking on the "Missions" link, I want it to redirect to the homepage with the "Missions" tab selected (with the "current" class).

This project is built using Ruby on Rails, however, I am seeking a jQuery/JavaScript solution for this problem.

Answer №1

One way to implement this is by utilizing a hash value such as /myprofile#projects or a request parameter like /myprofile?tab=projects. Afterwards, you can use JavaScript to dynamically add the appropriate class to the element.

Utilizing Hash Values

$(document).ready(function() {
    var hashValue = window.location.hash;
    if (hashValue) {
        // Determine which tab to display based on the hash value
    }
});

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

Anguar server encountered a startup issue and failed to initialize

My server.js file looks like this: var express = require('express'), api = require('./api'), app = express(); app .use(express.static('./public')) .use('./api', api) .get('*', ...

Angular: Compilation of SCSS/SASS results in unexpected whitespace issues

I am encountering an issue with whitespace being added to the CSS after compiling a *.scss file in my Angular 7 project. This unwanted whitespace is causing incorrect results in the UI. To replicate the problem, you can visit... ...and copy and paste the ...

Exploring the world of web scraping by using Python to loop through HTML elements

Created a Python script to extract information from the website regarding its asset listings. So far, I have successfully retrieved the name of the first coin "Bitcoin," but I'm unable to get the ticker. With 27 pages on the site, each containing 40 ...

What is the best way to send props to a React component?

Sorry for the inconvenience of asking for help with finding an issue in my code, but I'm facing challenges while learning React. I am attempting to pass a variable named hashRoute to a component in react. However, every time I try to access the prop ...

Running a setInterval function with Jquery when the window is minimized

I have implemented an image slider that uses a jQuery function setInterval() to replace images at timed intervals. However, I encountered a small issue where the function continues to run even after minimizing the browser window. Upon restoring the window, ...

Issue with React's handleChange function in two separate components

I need assistance with calling the event handleChange from a second Component This is my principal component: const [mainState, setMainState] = useState({ stepValue: 1, saleDateVal: new Date(), customerVal: '' }); function moveNextStep() { ...

Utilize Bootstrap's empty field validation for various other validation purposes

After downloading a bootstrap theme for my website, I noticed an elegant validation feature for required fields. When a field is left empty, a red exclamation mark appears behind the input, and hovering over it reveals the error message inside the field. ...

Utilize useMediaQuery for identifying various breakpoints in your design

Currently, I am working on detecting multiple breakpoints in my application to ensure dynamic column generation on a Grid. Although I have managed to accomplish this task, the code appears somewhat repetitive. Is there a method through which I can simpli ...

Why isn't my output being shown on the screen?

Why is the output (refresh value) not being displayed? function myFunction() { $a = document.getElementById("examplehtml").value; document.write("<big><bold>"); document.write($a); document.write("</bold></big>"); $b = ...

The splash screen fails to show up when I launch my Next.js progressive web app on iOS devices

Whenever I try to launch my app, the splash screen doesn't show up properly. Instead, I only see a white screen. I attempted to fix this issue by modifying the Next Metadata object multiple times and rebuilding the PWA app with no success. appleWebApp ...

A guide on using wrapAll within an each loop in jQuery

I have a series of div elements in my HTML code: <div class="mainClass class_1"></div> <div class="mainClass class_1"></div> <div class="mainClass class_2"></div> <div class="mainClass class_2"></div> <di ...

Secret method to successfully reach a function designated within the load scope

Check out my code : <a href="javascript:void(0);" onclick="myFunction(this)">Call Function</a>​ $(window).load(function () { function myFunction(param) { console.log("called"); } }); It seems like I'm unable to access ...

Having a negative position while using overflow auto can cause the element to disappear from

My current issue arises when utilizing negative positioning (e.g. top:-20px) within an absolute div while adding overflow:auto to the parent div. The text becomes hidden in all browsers. Unfortunately, due to the structure of my application, it is not fe ...

Employ Ajax for updating a database using a Select option instead of a form with a button

My goal is to utilize ajax in order to select an option and store the data in a database, rather than using a select within a form along with a button. This approach is necessary because I have one select for each row, and every time I change the selected ...

Having trouble retrieving JSON data from a local file using AJAX and jQuery

I am currently facing an issue with passing the content of json.txt in my PHP project folder to JavaScript. It was working fine yesterday, but today it seems that the browser is preventing it somehow... EDIT : Just to clarify, everything is on localhost, ...

What could be causing my bootstrap cards to have varying lengths?

I'm currently working on a project that requires me to apply a specific responsive design using HTML Bootstrap classes. I've managed to format it the way I want, but I'm puzzled as to why the width of my cards within rows is inconsistent in ...

Express.js: Defining a base route can cause issues with resolving static files

I'm currently working on a project using express.js and react.js, but I've encountered some issues that I can't seem to find solutions for. I have set up a base directory where the express server is located, and within that, there's a ...

Safari now fully embraces Flexbox technology

My flexbox code works well in Chrome and Firefox, but unfortunately it's not performing well in Safari. Despite trying various prefixes, I couldn't achieve the same simple order. How can I modify or add to my code so that it functions normally in ...

Directive fails to trigger following modification of textarea model

There is a block of text containing newline separators and URLs: In the first row\n you can Find me at http://www.example.com and also\n at http://stackoverflow.com. The goal is to update the values in ng-repeat after clicking the copy button. ...

Rendering the page using ReactDOM.render

Just started with ReactJS, I'm struggling to figure out why my page isn't displaying anything - <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> ...