I am playing around with TypeScript and am trying to create a script that will fetch the HTML values of a div with class and id.
However, I am able to get the result for a class but I cannot fetch the result using getElementById.
The html looks as following:
<button (click)="selectDiv()">select div</button> <div class="container" id="main-wrapper"> <p> Fetch me </p> </div> And the explore.ts file
selectDiv() { //create a new HTMLElement from nativeElement var hElement: HTMLElement = this.elRef.nativeElement; //now you can simply get your elements with their class name var allDivs = hElement.getElementsByClassName('container')[0]; var getSection = <HTMLElement>document.getElementById["main-wrapper"].innerHTML; console.log(allDivs); console.log(getSection); // returning nothing } getsection is giving me an error as follows:
ERROR TypeError: Cannot read property 'innerHTML' of undefined
ViewChildinstead of DOM interfaces such asgetElementsByClassNameorgetElementById. There are good reasons for this, which are too detailed to go into here.this.document.body.innerHTML += this.get_template_skeleton.template_code2;, once i change the code in need to catch a certain<div>.