Is it possible to access the function of elements from another element? polymer 1.0

Let's say I have element A

//imports
<dom-module id="element-A">
    <style></style>
<template>
    <content>
      //some content
    </content>
</template>

<script>
    // element registration
    Polymer({
        is: "element-A",
        aCustomFunction: function(e){
          //just some code
        }
    });
</script>

What if I want to access a function aCustomFunctionfrom another other element?

+4
source share
2 answers

You can do it the usual way, for example

if i have this item

<element-A id="someid"></element-A>

so i can go and do

 var element = document.getElementById("someid");
 element.aCustomFunction('someE');

or

 this.$.someid.aCustomFunction('someE');

In some cases, getElementById does not work. You can use the corresponding polymer api to find this element. The idea is that you do not need to do something special, but find the element and use it as an object.

+6
source

, behaviors. Polymer.

0

Source: https://habr.com/ru/post/1624814/


All Articles