On Tue, Nov 17, 2015 at 5:57 PM, Jim Wang <[email protected]> wrote:
> In jquery, we could control html elements
> like: $("button[name^='mybutton']"). then do something about it.
> With Polymer 1.0 - do we still need jquery? Can Polymer do all jquery's
> work?
>
You don't need jQuery, or Polymer for that, just do:
document.querySelector("button[name^='mybutton']")
Within a Polymer element we have a help for finding elements inside the
local dom: this.$(id) and this.$$(selector), which are roughly equivalent
to this.shadowRoot.querySelector('#id') and
this.shadowRoot.querySelectorAll(selector).
Since ids are useful again (because they're scoped to a shadow root), I'd
recommend using this pattern when you can:
<template>
<button id="mybutton">Click Me</button>
</template>
<script>
...
doSomething(this.$.mybutton);
</script>
Of course, Polymer also adds a bunch of helpers for declaratively adding
event listeners, data-binding to values, etc., so many times you might not
even need to get a reference in code.
> Cheers!
>
> Follow Polymer on Google+: plus.google.com/107187849809354688692
> ---
> You received this message because you are subscribed to the Google Groups
> "Polymer" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/polymer-dev/672d8255-7f87-4218-92cb-7b50fe543e81%40googlegroups.com
> <https://groups.google.com/d/msgid/polymer-dev/672d8255-7f87-4218-92cb-7b50fe543e81%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>
Follow Polymer on Google+: plus.google.com/107187849809354688692
---
You received this message because you are subscribed to the Google Groups
"Polymer" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/polymer-dev/CAEKsHmDyZuwr8hn%3DQrrJnK0kpCg%2BAgOr-eMO1YeGW9xMq%3DUP%2Bw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.