Reputation: 742
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
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
Reputation: 657108
This should do what you want:
toggle: function(id){
this.$[id].toggle();
}
Upvotes: 2