call other function in toaster onShown event

932 views Asked by At

I have below code to for toaster

    toastr.success("<br /><br /><button type='button' id='confirmationRevertYes' class='btn clear'>Yes</button>",'delete item?',
      {
          closeButton: false,
          allowHtml: true,
          onShown: function (toast) {
              $("#confirmationRevertYes").click(function(){
                hidepanel(); // not working
                this.hidepanel(); // not working
              });
            }
      });

I have one function outside

hidepanel(){
}

When trying to call inside toaster onShown method it throws error

hidepanel does not exist on type 'HTMLElement'.

How can this work?

Thanks

1

There are 1 answers

8
Sachila Ranawaka On

Assuming you have a function call hidepanel, use the => expression

toastr.success("<br /><br /><button type='button' id='confirmationRevertYes' class='btn clear'>Yes</button>",'delete item?',
  {
      closeButton: false,
      allowHtml: true,
      onShown: (toast) => {
          $("#confirmationRevertYes").click(() =>{ 
            this.hidepanel();  
          });
        }
  });