$('[data-tab-target]').each(function(){
var tab = $(this);
//...do stuff
});
Solution 1 :
Solution 2 :
I think you’re looking for something like this:
const tabs = $("[data-tab-target]");
tabs.each(function (index, tab) {
console.log(index);
console.log(tab);
});
// using arrow function
tabs.each((index, tab) => {
console.log(index);
console.log(tab);
});
// specific attribute
var target = $("[data-tab-target='1']");
// using for loop
for (var tab of Array.from(tabs)) {
console.log(tab);
}
for (var tab of [...tabs]) {
console.log(tab);
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.4/jquery.min.js"></script>
<div data-tab-target="1">1</div>
<div data-tab-target="2">2</div>
<div data-tab-target="3">3</div>
Solution 3 :
$('[data-tab-target]').each(function(index) {
console.log(index);
// Do something here
};
Jquery each function iterates through each of the DOM elements picked up by the query, you can then do something with each of these values.
$.each: https://api.jquery.com/each/
Problem :
const tabs = document.querySelectorAll("[data-tab-target]");
I then loop through the tab targets tabs.forEach(tab
I’m unsure how to grab all the data-tab-targets with jquery and then loop through all the individual tabs