.js tabbed menu links not working correctly

Hoping someone can help me with this please.
Having a strange problem with tabbed content not loading correctly unless I refresh the page.

I have a main navigation menu for the site which has some links which load a specific tab when they are clicked, that part works fine.
On the page with the tabbed section (services page) I also have the tabbed menu which loads the correct tabs when its supposed to.

The problem is when you are on the services page, if you click the links to the tabbed section from the main site navigation it does not work unless I reload the page for the browser after I’ve clicked the link.

Here’s the .js which I’m using to make the tabbed section work.

<script type="text/javascript">
                            $(function () {
    $(".tab_widget li:first").addClass("active");

    $(".tab_widget a").on('click', function (e) {

    var hash = $.trim( window.location.hash );

    if (hash) $('.tab_widget a[href$="'+hash+'"]').trigger('click');


Can anyone tell me how I can amend this to make it work from the main menu clicks even if the user is on the tabbed page?

Any help as always very much appreciated.


Hi sketchgal,

Is it possible for you to link to somewhere that we can see the code and try it out? It’s difficult to debug without being able to recreate the problem.

Here’s a link to the page where you can see the problem with the drop down menu at the top not working correctly but the tabbed side nav works.
Any help greatly appreciated with this.


Add this JS to your Services page:

$("ul.sub-menuitem a").on('click', function (e) {
    $('.tab_widget a[href$="'+this.hash+'"]').trigger('click');

The selector I’ve used here would obviously cause you problems if you add another dropdown menu to the site that uses the .sub-menuitem class, so you might want to add a unique id to the services menu to select on.

Thanks very much for the help with this fretburner.

I’ve put the code in below the code I already had on the page but it’s not working for some reason.

Heres the link to the page now, any ideas what else I need to change on it?


Thanks very much fretburner, your code works brilliantly!
I’d put it in the wrong place!

Moved it to within the function and it workd great!

Thanks again!