Question

I'm working with Twitter Bootstrap, I have a link which when clicked I want to open one of the accordian tabs (and scroll nice and smooth)

It works first time, if i open other tabs then try the link again i get a reference error saying 'openTab' is not defined.

Here's what I have so far:

HTML:

<a href='#reviews' class="star-ratingT" onclick="openTab()">Write a review</a>

jQuery:

$(function(openTab) {
$(".review-tab").trigger("click");
});
Was it helpful?

Solution

$(document).ready(function() {
    $(".stat-ratingT").click(function () { 
        $(".review-tab").trigger("click");
    });
});

OTHER TIPS

change

$(function(openTab) {

with

function openTab() {

Try

<script src="jquery.js"></script>
<script
$(function() {
  $(".star-ratingT").on("click",function(e) {
    e.preventDefault(); // cancel the actual link
    $(".review-tab").trigger("click");
  });
});
</script>

change this one:

$(function(openTab) {
    $(".review-tab").trigger("click");
});

to this:

function openTab() {
    $(".review-tab").trigger("click");
}

How about removing it from the A tag and just putting it in the jQuery as well?

$(".star-ratingT").click(function(){
    openTab();
});
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top