skip to Main Content

I need to get father after a click: i have this code html:

 <button mat-icon-button (click)="download($event)">

the code html generate is this:

  <button _ngcontent-wsc-c153="" mat-icon-button="" class="" aria-label="">
    <mat-icon _ngcontent-wsc-c153="" role="img" alt="download" class="" aria-hidden="true" data-mat-icon-type="font" aria-describedby="cdk-describedby-message-2" cdk-describedby-host="0">download_for_offline</mat-icon><!---->
</button>

in my ts file I do this:

 download(event) {
   
    console.log(event);

How I can get from event the father because event.target is mat-icon but I need get the father button?

2

Answers


  1. Try the following:

    download(event) {
      const parentButton = event.target.parentNode;
      console.log(parentButton);
    }
    

    Note: The term "father" is not commonly used in web development to refer to the parent element. Use the term "parent" instead.

    Login or Signup to reply.
  2. You can use parentElement.

    download(event) {
      console.log(event);
      const parent = event.target.parentElement; //parent button
    }
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search