Show the correct active tab based on the href attribute is not working properly
I have this jquery to give the class active to a tab when the url has the correct hash.
So the code is working if is just for the #myTickets like:
- var path = window.location.href;
- $('.registration_form_list a').each(function () {
- var hash = $(this).attr('href').split('#')[1];
- if (this.href === path) {
- $('.registration_form_list a').removeClass('active');
- $('a[href="#myTickets"]').addClass('active');
- }
- });
But I want to have this dynamic, so I change to:
- var path = window.location.href;
- $('.registration_form_list a').each(function () {
- var hash = $(this).attr('href').split('#')[1];
- if (this.href === path) {
- $('.registration_form_list a').removeClass('active');
- $('a[href="# '+hash+'+).addClass('active');
- }
- });
Do you know why?