Reputation: 5911
I want to grab an element by its ID. My template looks like this:
<template>
<h2>Welcome</h2>
<div id="toGrab"></div>
</template>
I tried using jQuery but the below snippet doesn't work:
$('#toGrab').dosomething();
Any idea?
Upvotes: 3
Views: 5482
Reputation: 31
In Polymer 3:
ready() {
super.ready();
const x = this.shadowRoot.getElementById('divID');
}
Upvotes: 3
Reputation: 657138
If you code is inside the Polymer element, just do
var div = this.$.toGrab;
Upvotes: 4