So I have an unordered list of links, and I need to say "If any of these links are clicked for the first time do this, else do this" and I don't mean any individual link in the list, if just one of these items is clicked, that is the first click for all of them.
$('.idTabs li a').one("click", function() {
do this;
});
This works, but only for each individual link in the list. It will work on click of list-item-1 and not appear again, if I click list-item-2 it will do it once and not appear again. What I need is to click on list-item-1 and have it not appear again for any other list-item-#.
Further background to better understand: I have a list navigation that expands a hidden sub-navigation when you click on one item, after clicking that first item, the sub-navigation appears, and after it appears—clicking on any other parent item opens it's corresponding sub-navigation like tabs.
You could use .data() to store a boolean value, associated with the unordered list, indicating if it is the first click or not:
$('.idTabs li a').on("click", function() {
var $idTabs = $(".idTabs");
var clicked = $idTabs.data("clicked");
if (!clicked) { // first click
$idTabs.data("clicked", true);
console.log('First click');
} else {
console.log('Not the first click');
}
});
DEMO.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With