Help With URL parameter to open tabs info

Posted on 2011-03-02
Last Modified: 2012-05-11
Need some help with the script below. I would like to add the ability to pass a url parameter that would open one of the tabs based on ex URL#tabinfo parameter. Any help would be great thanks.
(function ($) {
    function getactTabAnc() {
        return this.find('.active>a')[0];
    function getContentId(tabAnchorS) {
        return $(tabAnchorS).attr('href').replace('#', '');
    function applyStyles(newActTabAnc) {
        var actTabAnc = newActTabAnc || getactTabAnc.apply(this), activeContentId = getContentId(actTabAnc);
        this.find('a').each(function () {
            var $cur = $(this), curContentId = getContentId(this);
            if (activeContentId === curContentId) {
                $('#' + curContentId).show();
            else {
                $('#' + curContentId).hide();
    $.fn.tabs = function () {
        return this.each(function () {
            var $tabTainer = $(this);
            $tabTainer.find('a').click(function (e) {
                var actTabAnc = getactTabAnc.apply($tabTainer), isActive = this === actTabAnc;
                if (!isActive) {
                    applyStyles.apply($tabTainer, [this]);

  <ul id="tabsHolder">
    <li class="active"><a href="#tabId1">Header 1</a></li>
    <li><a href="#tabId2">Header 2</a></li>
   <div id="tabId1">Content 1</div>
   <div id="tabId2">Content 2</div>

Open in new window

Question by:yando18
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 3
LVL 40

Expert Comment

ID: 35024251
you can get the parameter value by name from the URL's querystring

then you can set the tab related to it to active

Author Comment

ID: 35024276
How would you apply this to the script attached?
LVL 40

Expert Comment

ID: 35024286
what is the relation between the parameter value and tab ?
Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.


Author Comment

ID: 35024319
Ideally I would like the parameter to open the tab. For example would open up the second tabs content.
LVL 40

Accepted Solution

gurvinder372 earned 500 total points
ID: 35024431
In that case you just need to add this line before line 2

$("#" + location.hash).parent().addClass("active");

Author Comment

ID: 35027986
So I added that code to the second line however it does not seem to work. When I added #tabId2 to the end of the URL the tab does not open. Thoughts? Thanks again.

Author Comment

ID: 35031254
Does anyone have any thoughts about this issue? I could really use some advice.

Author Comment

ID: 35032209
So I got it to work by using:

However I need remove the active class placed on the li by default.


Author Comment

ID: 35040253
So I was able to get the tabs to display using the code below, which has been altered a bit. The tabs active state changes however the tabs content is not displaying. Instead the default tabs content is displayed. Any help would be great. Thanks for your help with this.
<script type="text/javascript">
           $(document).ready(function () {
               var hash = location.href.split("#")[1];
               if (hash) {
                   $('#tabsHolder li').removeClass('active');
                   $("a[href=#" + hash + "]").parent().addClass("active");
               } else {
                   $("#tabsHolder li:first-child").addClass("active");

Open in new window


Author Closing Comment

ID: 35077888
I used another solution. Thanks

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question