Search code examples
polymerweb-component

Web component, how to get an element by Id?


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?


Solution

  • If you code is inside the Polymer element, just do

    var div = this.$.toGrab;