The_Ogre
The_Ogre

Reputation: 117

Parsing a value of a variable onto another variable in javascript

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

Answers (1)

Irfan wani
Irfan wani

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

Related Questions