Having trouble with a new tab not responding to clicks - Could be a jQuery problem for beginners

Instead of using the generic tab function provided by my website builder, I decided to take matters into my own hands and build one from scratch. While I am more comfortable with CSS than scripts at the moment, my attempt at creating a custom tab function is visually appealing but lacks functionality on clicks.

Check out the JSFiddle here: https://jsfiddle.net/6oq3t9ev/1/

<ul class="tab_conts" id="recent" style="display: block;">
  <li class="tab_cont">
    <a href="/test" class="tab_cont_link">Test</a>
    <a>
      <desc>Testing</desc>
    </a>
  </li>
   <li class="tab_cont">
    <a href="/test" class="tab_cont_link">Test</a>
    <a>
      <desc>Testing</desc>
    </a>
  </li>
</ul>

<ul class="tab_conts" id="new" style="display: none;">
 <li class="tab_cont">
    <a href="/test" class="tab_cont_link">Test</a>
    <a>
      <desc>Testing</desc>
    </a>
  </li>
   <li class="tab_cont">
    <a href="/test" class="tab_cont_link">Test</a>
    <a>
      <desc>Testing</desc>
    </a>
  </li>
   <li class="tab_cont">
    <a href="/test" class="tab_cont_link">Test</a>
    <a>
      <desc>Testing</desc>
    </a>
  </li>
</ul>

$(document).on("ready int:ready", function() {
var e = $(".tab_name"),
  t = $(".tab_conts").hide();
e.prependTo(".tabs-cn"), e.click(function(n) {
  n.preventDefault();
  var i = $(this),
    r = e.index(i);
  e.removeClass("tab_name-active"), i.addClass("tab_name-active"), t.hide().eq(r).show()
}), e.first().click() })

Answer №1

To achieve the desired result, you can use the following code snippet:

$(document).ready(function(){
    $('.tab_item').on('click',function(){
        var id = $(this).attr('id');
        $('.tab_content').css({'display':'none'});
        $('#' + id).css({'display':'block'})
    });
});

Remember to include jQuery in your document head for this to work properly.

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.2/jquery.min.js"></script>

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

Ways to differentiate the file progress associated with each task

When it comes to jQuery File Upload, there is an essential progress event that provides a data object indicating the progress for each file. I am currently incorporating file and progress bars into my UI using the add() event, and I need to update their r ...

Issues with populating Asp.net Grid using JSON /AJAX

I'm looking for a way to populate a grid using JSON/Ajax without using templates. The rest of the code is functioning properly. Edit: Do I need to bind the grid with DataSource/DataBind? Can it be achieved without doing so? Below is the success func ...

Retrieving information from Prismic API using React Hooks

I'm having trouble querying data from the Prismic headless CMS API using React Hooks. Even though I know the data is being passed down correctly, the prismic API is returning null when I try to access it with React Hooks. Here is my current component ...

How can I redirect to a different URL when the dropdown selection changes?

<form action="myservlet.do" method="POST"> <select name="myselect" id="myselect" onchange="this.form.submit()"> <option value="1">One</option> <option value="2">Two</option> <option value="3"& ...

The target of the event in Internet Explorer 6

I am currently facing a challenge with an event handler that I have attached to an element in order to capture a bubbled click event. The key issue here is the need for a dependable method to retrieve the element that captured the event, rather than the el ...

MongoDB does not return any results for the query and returns

I am facing an issue while trying to retrieve information from my mongodb database. Despite successfully fetching data from the "users" collection, I keep getting an empty object for other collections. var mongoose = require('mongoose'); var Sch ...

Tips for saving the web address and breaking down each word

Hello, I am familiar with how to store URL parameters using the following JavaScript code. However, I am wondering if there is a way to store each word that comes after a slash in a URL. For example, let's consider the URL: http://localhost:9000/Data ...

Leveraging content_for alongside ajax/JQuery to dynamically refresh sections of a webpage

Gradually, I have been delving into the world of Mojolicious and Perl with the invaluable assistance from the knowledgeable individuals on this platform. Currently, my focus is on finding the optimal approach to updating specific sections of my webpage dyn ...

Is it possible to combine Ajax, JS, HTML, PHP, and MySQL in a single project?

I am looking to create a web application and wondering if I can integrate Ajax, JavaScript, HTML, PHP, and MySQL all together? ...

Is it possible for the variables in my php website to be overwritten if two users from different locations are accessing it simultaneously?

I am creating a PHP quiz where users can choose a category and see questions from that specific category in the database. I have a couple of concerns about this: Is it possible to show questions individually in PHP without the need for JavaScript? If tw ...

Exporting a class from an index.ts file may result in a problem where the injected constructor is

Utilizing an index.ts file to manage exports, following the guidelines outlined in the Angular 2 style guide (https://github.com/mgechev/angular2-style-guide/blob/master/old/README.md#directory-structure), has been successful throughout my application deve ...

Tips on choosing the initial nested element

Currently, I am working with cheerioJS, a library that shares selectors with JQuery. Given this, my query pertains to JQuery. In my HTML code, there are nested span tags where arbitrary tags may be present between them. For example: <span> <p&g ...

Run Javascript code if a specific CSS class is present on an element

Whenever a user enters an incorrect value into a textbox on my page, an error message is displayed within a div with the class 'validation-errors'. I'm looking for a solution to trigger a javascript function (which adds a CSS property to a ...

Fresh Regular Expression created from a readable string

I can't figure out why rg = new RegExp(`/${a}.*${b}/`) isn't functioning properly here, while rg = /\(.*\)/ is working fine. let a = '\('; let b = '\)'; let rg; //rg = new RegExp(`/${a}.*${b}/`); // doesn&a ...

Testing nested mocked functions can be achieved by setting up the necessary mocks

How can I create tests for mocked functions within a mocked function? My goal is to verify that my publish mocked function is called only once. jest.mock('amqplib', () => ({ connect: jest.fn(() => Promise.resolve({ createChannel: jes ...

What are the steps to navigate through a PDF displayed in an embed tag in Chrome?

When a link is clicked, a PDF opens in a new tab in Chrome. The PDF may have multiple pages and is embedded within an <embed> tag. My goal is to use JavaScript or jQuery to scroll through the PDF in the Chrome browser's developer console. Howeve ...

Retrieve the id of the clicked hyperlink and then send it to JQuery

<a class = "link" href="#" id = "one"> <div class="hidden_content" id = "secret_one" style = "display: none;"> <p>This information is confidential</p> </div> <a class = "link" href="#" id = "two" style = "display: non ...

Peer-to-peer Ajax image sharing

Currently, I'm utilizing Ajax to fetch images from a remote server. Initially, I attempted this by directly using the URL of the remote server - resulting in the returned image being a string (given that's how Ajax communicates). To rectify this, ...

Retrieve information and functions from one component in a separate component

I currently have two components: ContainerSidebar.vue <!-- Sidebar --> <div id="b-sidebar"> <div class="change-image"> <img :src="profile.avatar != null ? profile.avatar+'#&apo ...

Is it possible to generate grid options dynamically for various tables within AngularJS using ui-grid?

I have developed a service for ui-grid table functionality. Currently, I am able to use this service on a single page but now I want to extend its usage to multiple pages, each with different table data. How can I pass grid options and JSON data for multip ...