GravyPlaya
GravyPlaya

Reputation: 128

How do I assign a var from passed in function var?

function getTabContent(tabId){
    var c = tabbar._content.tabId.innerHTML;
    return c;
}

I want var c to evaluate to the passed in var. So if I call getTabContent('dash'). var c will be the value of tabbar._content.dash.innerHTML from the DOM. NOT the string tabbar._content.dash.innerHTML.

How do I do this?

Upvotes: 1

Views: 54

Answers (1)

Matt Ball
Matt Ball

Reputation: 359846

Use square bracket syntax.

function getTabContent(tabId){
    return tabbar._content[tabId].innerHTML;
}

Upvotes: 5

Related Questions