我想通过ID获取元素。我的模板如下所示:
<template>
<h2>Welcome</h2>
<div id="toGrab"></div>
</template>
我尝试使用jQuery,但下面的代码片段不起作用:
$('#toGrab').dosomething();
有什么想法吗?
答案 0 :(得分:5)
如果您的代码在Polymer元素内,请执行
var div = this.$.toGrab;
答案 1 :(得分:1)
在聚合物3中:
ready() {
super.ready();
const x = this.shadowRoot.getElementById('divID');
}
答案 2 :(得分:0)
...也
var div = this.$$("#toGrab");