0

I have a page that contains tabs of information. In some circumstances i need to open with a specific tab active, so i assigned a unique div and class to it and have #reviews appended to the url. The page scrolls correctly to have the tabs in view, but I can't figure out how to open the tab ONLY when #reviews is in the url.

If i add

<script>  
$(document).ready(function() {
$(".rTab").trigger('click');
});
</script>

to the div the tab opens on every page load. So, is there a method of checking for a #url to fire the trigger() ?

Thanks

Steve Price
  • 600
  • 10
  • 28

3 Answers3

1

Something like this should work depending on what you need..

Without jQuery

if(window.location.hash == '#hashurlhere'){
    var trigger = document.getElementsByClassName("rTab");
    trigger[0].click();
}

With

if(window.location.hash == '#urlhere'){
    jQuery(".rTab").trigger('click');
}
russell
  • 176
  • 1
  • 12
0

Try this one

$(document).ready(function() {
  $("a[href=#reviews]").trigger('click');
});

It may help you.

Manish Jangir
  • 5,329
  • 4
  • 42
  • 75
0

you could do something like this:

   if(window.location.hash == $(this).attr('href')) $(this).trigger('click');

I found this code a while ago, credits to the author.

Evert Arends
  • 142
  • 1
  • 11
  • Woops mybad, I wrote the comment, searched for the code on my pc, and found this one, and I was like 'Hey, this suits better!' :p thanks for mentioning it. – Evert Arends Sep 29 '15 at 13:48