Zbigniew Kisły
Zbigniew Kisły

Reputation: 742

using variables in Polymer functions

I have a code like this in Polymer object:

toggleList: function(){
    this.$.list.toggle();
}
toggleSign: function(){
    this.$.sign.toggle();
}

Can I easily implement function toggle(var element) to toggle different types of components?

@edit:

here is what I want to accomplish

toggle: function(element-id){
    this.$.{{element-id}}.toggle();
}

I want to use one function with argument instead of two functions with different names

Upvotes: 0

Views: 55

Answers (2)

CuriousMind
CuriousMind

Reputation: 3173

Polymer offers $$ to specify selector for querying dom. You can find more details here.

So in your case, you can have something like

this.$$("#list").toggle();

Upvotes: 1

Günter Zöchbauer
Günter Zöchbauer

Reputation: 657108

This should do what you want:

toggle: function(id){
    this.$[id].toggle();
}

Upvotes: 2

Related Questions