The question has been asked a few times before, but none of them are similar to my scenario.
I have jQuery Tabs control that loads my tabs via ajax:
<div id="tabs">
<ul>
<% if (AccessControll.HasAccess(Url.Action("ViewSchemeInformation","Scheme"))){%>
<li><a id="tab_1" href="<%= Url.Action("ViewSchemeInformation","Scheme", new {schemeNumber = Model.SchemeNumber}) %>">Information</a></li>
<%}%>
<% if (AccessControll.HasAccess(Url.Action("SchemeUpdate", "Scheme"))){%>
<li><a id="tab_2" href="<%= Url.Action("SchemeUpdate","Scheme", new {schemeNumber = Model.SchemeNumber}) %>">Update</a></li>
<%}%>
<%if (AccessControll.HasAccess(Url.Action("MinimumRequirements","Scheme"))){%>
<li><a id="tab_3" href="<%= Url.Action("MinimumRequirements","Scheme", new {schemeNumber = Model.SchemeNumber}) %>">Minimum Requirements</a></li>
<%}%>
</ul>
These tabs are shown based on access, so my tab index's are never the same, hence I have added an id
to each href
.
I link to this specific page from various places and each link must go to this page and select the tab it refers to.
My url will look something like this: http://localhost:34412/Scheme/ViewSchemeDetails/BS-000469800000?activeTab=1
How can I select the tab using jQuery based on the activeTab parameter in my querystring?
Note that number in the querystring always corresponds to the id of my href
.
var selectedTab = $("#TabList"). tabs(). data("selected. tabs");
jQuery UI tabs() method is used to change the appearance of HTML elements inside the page. This method traverses the HTML code and adds new CSS classes to the element to give them appropriate style.
disable( index )Returns: jQuery (plugin only) To disable more than one tab at once, set the disabled option: $( "#tabs" ). tabs( "option", "disabled", [ 1, 2, 3 ] ) .
Get the query string:
var queryString = window.location.search;
Get the activeTab
part:
var activeTab = queryString.match(/\bactiveTab=([^&]*)/)[1];
Select the tab with the right ID:
$('#tab_' + activeTab).click();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With