Adding Dom Attribute error

Hi, i am trying to add the following:

$$('a').attr('@swipeout:deleted', 'onDeleted');

But I am getting a error which says:

Uncaught (in promise) DOMException: Failed to execute ‘setAttribute’ on ‘Element’: ’ @swipeout:deleted’ is not a valid attribute name.

Without the @ it is working fine, but then I don’t have what I need. Anyone who knows how to add maybe with another manner or something else what I can do to achieve the goal here?

Because

It is not a valid attribute. If you want to add event listener then:

$$('a').on('swipeout:deleted', () => {
  console.log('do something');
});

Thanks for your reply again, but that is not working in a template page. For template pages I used the @swipeout:deleted . Is there another way to use the code below in a template page?

$$(‘a’).on(‘swipeout:deleted’, () => {
console.log(‘do something’);
});

Do you get my problem? Because I am still stuck…