【发布时间】:2019-11-17 19:35:16
【问题描述】:
我会在每个节点元素上添加一个矩形
rect 仅添加在最后一个元素中。
ngAfterViewInit() {
let rect : NodeList = this.synoptic.nativeElement.querySelectorAll("#stops g");
let rect2 = document.createElementNS('','rect');
rect2.setAttribute("fill","none");
rect.forEach((elm : Node) => {
console.log(elm.firstChild) #### Well selecting the first element
elm.insertBefore(rect2,elm.firstChild);
console.log(elm) ####rect added
})
### rect is awailable only in the last elm
}
编辑我正在使用 angular 并且我的代码在 ngAfterViewInit() 钩子内运行
Here stackblitz 演示
【问题讨论】:
标签: javascript angular dom svg jquery-selectors