$(document).ready(function() {
$(".stat-ratingT").click(function () {
$(".review-tab").trigger("click");
});
});
how to call a function onclick (reference error)
-
06-10-2022 - |
Frage
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");
});
Lösung
Andere Tipps
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();
});
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow