我想获得具有相同类名的div的offsetWidth:-“ offer-ads-wrap”。我正在获取HTMLCollection列表,长度为零。如何获得offsetwidth?我的html代码是:-
<div class="offer-ads-area" *ngFor="let singleRest of restaurantListByTag">
<div class="wraper">
<div id="offer-ads-wrap" class="offer-ads-wrap add_sec">
<h3>{{singleRest.name}}</h3>
<ng-template #prev >
<i
class="fa fa-arrow-circle-left fa-4x pointer" aria-hidden="true">
</i>
</ng-template>
<div (window:resize)="onNewResize($event)"
ng2-carouselamos
class="slides-wrapper"
[width]="newDynamicWidth"
[items]="singleRest.tag_map"
[$item]="item"
[$prev]="prev"
[$next]="next">
</div>
<ng-template let-item let-i="index" #item>
<div class="items">
<a href="#">
<figure><img src="../../assets/images/ad3.jpg"></figure>
<span class="menu-info">
<h5>{{ item.res_name }}</h5>
<span>{{ item.res_title_tag }}</span>
</span>
</a>
</div>
</ng-template>
<ng-template #next >
<i
class="fa fa-arrow-circle-right fa-4x pointer" aria-hidden="true"></i>
</ng-template>
</div>
</div>
</div>
在我的TS文件中,我正在编写以下代码:-
let newDynamicWidthEl = document.getElementsByClassName("offer-ads-wrap");
console.log(newDynamicWidthEl);
在控制台中,我的输出是:-
HTMLCollection [0] 0:div#offer-ads-wrap.offer-ads-wrap.add_sec 1:div#offer-ads-wrap.offer-ads-wrap.add_sec 2:div#offer-ads-wrap.offer-ads-wrap.add_sec 3:div#offer-ads-wrap.offer-ads-wrap.add_sec 长度:4 原始:HTMLCollection