Refresh tab URLs for dynamic tabs with jQuery UI

Utilizing jQuery UI dynamic tabs in my application requires updating the URL hash value when a user clicks on a tab.

After researching solutions on SO, like link1 and link2, I attempted the following approach:

Javascript:

$( "#tabs" ).tabs({
    select: function(event, ui) {                   
        window.location.hash = ui.tab.hash;

        if ( ui.index == 0) // its preloaded
                return;                               
    }
});

HTML:

<div id="tabs" > 
    <ul>
        <li><a href="#tabs-1"   > Tab 1  </a></li>
        <li><a href="Home/Test1"> Tab 2  </a></li>
        <li><a href="Home/Test2"> Tab 3  </a></li>            
    </ul>
    <div id="tabs-1">
        Some Text
    </div>
</div>

This script updates the URL based on the href value of each tab. However, it results in URl hashes like #ui-tabs-1 and #ui-tabs-2 instead of #Employee.

Anyone have a solution for this issue?

Answer №1

After experimenting with various methods, I discovered the most straightforward solution is to include a name property in the anchor element. Here's how you can modify the HTML section:

<div id="tabs" > 
    <ul>
        <li><a href="#tabs-1"   > Tab 1  </a></li>
        <li><a name ="Employee" href="Home/Test1"> Tab 2  </a></li>
        <li><a name ="Address"  href="Home/Test2"> Tab 3  </a></li>            
    </ul>
    <div id="tabs-1">
        Some Text
    </div>
</div>

The javascript functionality will remain unaltered.

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

When I click on .toggle-menu, I want the data-target to have a toggled class and the other divs to expand

Looking to achieve a functionality where clicking on .toggle-menu will toggle a class on the specified data-target element and expand other divs accordingly. jQuery(document).ready(function() { var windowWidth = jQuery(window).width(); if (win ...

Only wrap certain elements if they consist of two specific items

<div class="section"> <label>Title: </label> <input type="text" /> </div> <div class="section"> <label>Text: </label> </div> My goal is to enclose the label + input within an additional div ...

Choosing elements in jQuery

Having some trouble with the subnav on my current website project. I think the issue lies in how I am selecting items in my jquery code. It seems like a small fix that needs to be made, but I'm unsure of the correct approach. http://jsfiddle.net/ZDEr ...

Troubleshooting a problem with conditional statements using AJAX and jQuery in Rails

By leveraging the power of jquery and ajax, I am able to dynamically display new tweets without having to refresh the page. However, a challenge arises when it comes to including a delete button based on whether the current user is viewing their own profil ...

Struggling to effectively align the footer div in a responsive design

Check out this GitHub link to access the HTML file and CSS: https://github.com/xenophenes/pgopen-splash2016 I'm facing an issue with the footer text alignment. Despite my efforts, I can't seem to center it properly as it keeps appearing slightly ...

Utilize jQuery to extract data from a Steam page in JSON format

Although I have researched extensively on this topic, it is still not functioning as desired. I came across this Steam page in JSON format. My aim is to extract the lowest_price variable without using PHP as I am incorporating it into my Chrome extension. ...

Is it necessary to include the 'html' and 'body' tags in a WordPress Page Template?

Currently, I'm in the process of creating a unique Page Template for my WordPress website. In the file named newpagetemplate.php, I have included only this code: <html> <body> <?php /* Template Name: CustomPage */ ?> <div> ...

An issue arose when attempting to load the page using jQuery

Currently, I am implementing the slidedeck jquery plugin on my webpage to display slides. While everything is functioning properly, I am facing an issue with the CSS loading process. After these slides, I have an import statement for another page that retr ...

Prevent jQuery UI dialog from adjusting its position relative to the browser when scrolling

When I launch a jQuery UI dialog, the position of the dialog changes when I scroll the browser. How can I make it remain in the same position relative to the browser window? ...

Issue with jquery selector function when handling ajax response containing HTML data

Within my jquery code, I have implemented an ajax get function to retrieve the html code of a specific page. My objective is to extract a particular element from this html content. However, when attempting to do so, jquery throws the following error: SCRI ...

What are the best practices for utilizing the JQuery hasData() method effectively?

I have created a simple front-end web application where clicking a button triggers a GET Request to the Foursquare API, and then AJAX stores some of the response data into a div in the following manner: checkinsCount[i] = data.response.venues[i].stats.che ...

Is there a way to maintain the loop filters in archive.php when using AJAX?

I've been following a tutorial on using AJAX with jQuery and WordPress to add posts to my Packery.js layout. It's working perfectly on my home page, but I'm running into issues when trying to implement it on my archive pages. Instead of disp ...

What is the best method for extracting individual JSON objects from a response object and presenting them in a table using Angular?

After receiving a JSON Array as a response Object from my Java application, I aim to extract each object and display it on the corresponding HTML page using TypeScript in Angular. list-user.component.ts import { HttpClient } from '@angular/common/h ...

Angular 8: Implementing Form Validation with a Boolean Flag

Within my HTML code, I have a function (change)="limitUser($event)". In Typescript, I utilize a for loop to iterate through each element and determine if the value is less than 10. If it exceeds 10, the inValid = true condition is set. All form fields in m ...

"Creating dynamic radio buttons within a dynamic table using Ajax and jQuery: a step-by-step guide for toggling

Looking to generate a dynamic html table with data retrieved from a web method in asp.net using Ajax jQuery. One of the fields is a boolean value that needs to be associated with radio buttons. However, encountering an issue where setting attributes like ...

Discover the step-by-step process of retrieving an image through jQuery AJAX in Laravel 8

I'm facing an issue while trying to download images using jQuery/AJAX in Laravel 8. Although I am able to retrieve the image in the response, it isn't downloading as expected. Could someone please assist me in resolving this problem? Controller ...

What could be causing my ajax function to fail on yii2?

Hello there, I am seeking guidance on how to implement an ajax function in yii2. I am currently developing a product within the yii2 framework and wish to incorporate charts such as chartJs, googleChart, or d3. In the index file of the backend area (xx/xx ...

HTML double for-loop

While working on my website's HTML file, I encountered a challenge with nested for-loops. The first loop successfully checks the user's account and displays the corresponding data, and the second loop filters data starting with "Title:" and displ ...

Having trouble modifying a value in a form and submitting it to the following jsp page

I'm encountering an issue with changing the value in a hidden input element before submitting data to another JSP file (db.jsp) for processing. The value should be different depending on which button is clicked, but it always remains as the default va ...

When implementing datatables in Rails, the Id field integrated with "accepts_nested_attributes_for" functionality suddenly vanishes

Situation: Currently, I am utilizing simple_form to exhibit nested attributes of an association in rails. In order to enhance the edit form for the nested association, I have integrated the jquery-datatables gem using simple_fields_for. Here is a glimpse ...