0

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

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Md. Parvez Alam
  • 4,326
  • 5
  • 48
  • 108
  • What I think that happen is you are using some third party component. What will happen if you use a third party component is that `this` will be used inside that component. So to solve this you can put this `let me = this` above the toastr and then `me.hidepanel()` – Swoox Sep 26 '18 at 12:20
  • Thanks, your idea worked – Md. Parvez Alam Sep 26 '18 at 12:31
  • You're welcome :) Wasn't sure about the third party thing but I know this solution will work. – Swoox Sep 26 '18 at 12:47

1 Answers1

2

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();  
          });
        }
  });
Sachila Ranawaka
  • 39,756
  • 7
  • 56
  • 80