Reputation: 117
How can I parse the value of the constant
named currentTab
to that of the one named tabToActivate
?
function panel(event) {
const tab = event.currentTarget.closest(".tab");
const container = tab.closest(".login-sign");
const currentTab = event.currentTarget.dataset.forTab;
const tabToActivate = container.querySelector(".tabcontent[data-tab ='${currentTab}']");
console.log(tabToActivate)//outputs null perhaps due to improper parsing
}
Upvotes: 0
Views: 197
Reputation: 5094
Though your question is not too clear but i think i got it. We can only pass a variable in a string by using back ticks not quotes;
const tabToActivate = container.querySelector(`.tabcontent[data-tab="${currentTab}"]`);
Upvotes: 2