[Vuejs]-Javascript โ€“ Remove dynamic attribute

0๐Ÿ‘

You can get the list of all attributes by accessing this.$refs.template.$el.attributes ( which returns a NamedNodeMap)

If you know that these data attributes start with a certain prefix then you can do the following

const prefix = 'data-v';
for (const attribute of [...this.$refs.template.$el.attributes]) {
   if (attribute.name.startsWith(prefix)) {
     this.$refs.template.$el.removeAttribute(attribute.name);
   }
}

Leave a comment