I created a customized version of jQuery tabs, but I am looking for an external link to display the tab content and to style the original navigation

I've been experimenting with modifying a tabs script in jQuery that I came across. It seems like my attempt to enhance it has made things more complex than necessary. While I know creating tabs with jQuery is simple, I wanted to create my own version for learning purposes. The vertical tabs are functioning properly, but I also want the bottom links to behave the same way as the vertical navigation buttons - changing styling, including background color, etc. Additionally, there will be external links in the #footer section, so that needs to be considered as well.

Check out the JSFiddle here.

 $(function(){

 // Handling clicks on the vertical navigation on the left side of #content
 $('#sidemenu a').on('click', function(e){
 e.preventDefault();

 if($(this).hasClass('open')) {
  // Do nothing since the link is already open
 } else {
  var oldcontent = $('#sidemenu a.open').attr('href');
  var newcontent = $(this).attr('href');


  $(oldcontent).fadeOut('fast', function(){
    $(newcontent).fadeIn('fast').removeClass('hidden');
    $(oldcontent).addClass('hidden');
  });


  $('#sidemenu a').removeClass('open');
  $(this).addClass('open');
  }
 });

 // Handling clicks on the bottom links
 $('#footer a').on('click', function(e){
 e.preventDefault();
 var oldcontent = $('#sidemenu a.open').attr('href');
 var newcontent = $(this).attr('href');
 // Check if $(this) element links to a tab content or external
 if($(this).hasClass('open-tab')){
     if (oldcontent == newcontent){
        // If this tab is already open, do nothing to page
     } else {
         $('#content ' + String(oldcontent)).fadeOut('fast', function(){
         $(newcontent).fadeIn('fast').removeClass('hidden');
         $('#content ' + String(oldcontent)).addClass('hidden');
         });

         $('#sidemenu a').removeClass('open');
         $('#sidemenu a ' + newcontent).addClass('open');
     }
 } else{ 
   // Just use href link to whatever the element's href attribute is
   window.open($(this).attr('href'));
 }

 });
 });

Answer №1

The issue with the functionality of your links in #footer compared to those in #sidebar stems from a specific line present in both their click functions:

var oldcontent = $('#sidemenu a.open').attr('href');

This line is attempting to locate the current content by inspecting the classes of child elements within #sidebar.

If you select a link at the bottom, the subsequent link you click on (in either #sidebar or #footer) will fail to find the current content because it resides in #footer, not #sidebar. To rectify this, you must devise a method to set var oldcontent based on both #sidebar and #footer components.

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

What is the prescribed interface or datatype for symbol type in TypeScript with JavaScript?

I have a set of symbol values in JavaScript that I want to convert to TypeScript. // Defining object values in JavaScript const size = { Large: Symbol('large'), Medium: Symbol('medium') } What is the most efficient method to conv ...

Utilizing media queries to customize the appearance of a jQuery accordion widget

Hello, I'm struggling with implementing a jQuery accordion for mobile platforms that destroys itself on larger screens. While my code is mostly working, I've encountered two issues: The accordion only gets destroyed when the window is resized ...

Error: The function $(...).draggable is not recognized" and "Error: The object $.browser is not defined

I encountered an error stating, TypeError: $(...).draggable is not a function. To resolve this issue, I added jQuery as follows: <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script> < ...

I attempted to create a test scenario to verify that the length of the tasks array is not negative. However, when trying to test this using 'not.toBe' in the code below, an error was encountered

app.js var todos=[]; todos=['to-do one', 'to-do two']; module.exports=todos; app.test.js const todos=require('./app') test('should have a length of at least 0',()=>{ expect(todos.length).toBeGreaterThanOrEqu ...

Tips for aligning a single item to the center in a Bootstrap navigation bar that has the majority of items on the right

I am attempting to center the text "Welcome:" within the navbar without center aligning the entire navbar. I want the navbar to remain right aligned, but only the "Welcome:" portion should be centered. Here is what I have tried so far... <!DOCTYPE html ...

Encountering an issue in XtermJS where it is unable to read properties of undefined, specifically 'dimensions', while being used with NextJs version 14

UPDATE: Additional Details useEffect(() => { // let terminal; if (terminalRef.current) { const terminal = new Terminal({ fontFamily: "Menlo, Monaco, monospace", // fontSize: 12, // cursorBlink: true, ...

Error encountered in loop for concatenating html elements: identifier unexpectedly found (jquery + html + php)

I am attempting to concatenate HTML inside a variable within a loop and then return it populated. However, I am encountering an error: Uncaught SyntaxError: Unexpected token += in my code. <a style="cursor: pointer" id="addmore">More Entree ?</ ...

Is it possible to set up the material-ui datepicker to allow for the selection of dates spanning across multiple months without losing visibility of the current month?

Is it possible to choose dates within the same calendar week, regardless of whether they fall in different calendar months? For instance, selecting Friday from the previous month when the new month begins on a Saturday. To illustrate my point, let's ...

Improving iframe functionality in AngularJS

I've been experimenting with AngularJS to dynamically update an iframe whenever a query is triggered. It works like this: a query is made, the embed link is fetched from the database, and then it's used in the iframe alongside the title and video ...

Is there a way to return two separate functions within a single function that can be rendered as two distinct components in a React application without one function overriding the other?

I'm currently working on a react header that uses conditional rendering to show different elements based on the URL or user login status. However, I'm facing an issue where only one button is being rendered instead of two side by side in my defau ...

carousel with a table nestled within

As a beginner in web development, I am faced with the challenge of displaying a table with more than 8 columns, containing lengthy data, on a small screen. To address this issue, I have devised an alternative layout. In this new layout, the two rightmost ...

Resizable dimensions for the dark mode switch

My latest project involves creating a toggle button for switching between light and dark themes using CSS, HTML, and JavaScript: id("theme-btn").addEventListener("change", function() { if (this.checked) { qs(".box").setAttribute('style', ...

Exploring the animation potential of HTML5 canvas and Javascript through utilizing putImageData with animated gifs

I am interested in modifying the image data of each frame in an animated gif while it is playing in a web browser, using HTML5 canvas and Javascript. For instance, I would like to convert every frame to grayscale dynamically as the gif plays. Is this achie ...

Troubleshooting the 'innerHTML' Issue in Your Python Selenium Script

My Python Selenium script for sending emails via Gmail is throwing an error, and I need some assistance to resolve it. The error details are as follows: Traceback (most recent call last): File "C:\Users\Administrator\Desktop\New ...

Angular allows for dynamic sourcing of iframes

I have encountered an issue while trying to integrate a payment system with Angular. The payment gateway API I am using provides the 3D Secure Page as html within a JSON response. My approach is to display this html content within an iframe, however, the h ...

Tips for closing 2 models in a React application

Currently, I am working on a project using ReactJs. One of the functionalities I am implementing is generating a user's gallery when the user clicks on their avatar. To achieve this, I am utilizing the react-grid-gallery package along with semantic ui ...

Links are functional in browsers, but seem to be unresponsive on iPad devices

I'm currently developing a website that allows users to navigate using swipe gestures. Each slide contains multiple links that should redirect users to different locations upon clicking. However, I've encountered a bizarre issue where the links a ...

The requested path /releases/add cannot be located

In my CRUD application, I have a feature that allows users to create releases by adding a version and description. This is achieved through a button and input fields for the details. <button (click)="addRelease(version.value, description.value)" [d ...

Obtain the latest NPM package versions

I am currently seeking a way to compile a comprehensive list of all major versions that have been released for a specific NPM package. By utilizing the following API link, I can retrieve a list of available versions which includes both the major and exper ...

Tips for showing more rows by clicking an icon within an Angular 2 table

When I click on the plus (+) button in the first column of each row, only one row expands. How can I modify it to expand multiple rows at a time? Thanks in advance. <div> <table class="table table-striped table-bordered"> <thead> ...