0

Is it possible to select the content inside of a Polymer <content> tag using JQuery? If not JQuery, are there any other ways?

<link rel="import" href="elements.html">
<script src="../bower_components/page/page.js"></script>
<script src="../bower_components/jquery/dist/jquery.js"></script>

<dom-module id="jager-pages">
    <template>

        <iron-pages id="pages" attr-for-selected="route">
            <content id="content">
                <!--Render Pages-->
            </content>
        </iron-pages>

    </template>


    <script>
        Polymer({
            ready: function () {
                var pages = $(this.$.pages);

                //Setup Routing
                $('[route]', pages).each(function (index, element) {
                    //Each of these elements should have been passed in as content and have a 'route' tag.
                    var route = $(element).getAttribute('route');
                    prompt(index + ': ' + route);

                    page(route, function () {
                        console.log('Routing to -> ' + route + '!');
                        $(pages).select(route);
                    });
                });

                page({
                    hashbang: true
                });
            }
        });
    </script>
</dom-module>

Here is my custom element where I need to make the JQuery(or otherwise) call to loop through the values of the "route" attributes present.

<jager-pages>
    <!--Pages-->
    <section route="/home">
        <h1>Home!</h1>
    </section>
    <section route="/info">
        <h1>Info!</h1>
    </section>
    <section route="/about">
        <h1>About!</h1>
    </section>

</jager-pages>

This is an example of the elements content.

I am able to select and wrap content with $(this.$.content), but $(this.$.content).find('[route]') doesn't return anything at all. It's as if the content was never added or something.

Mr Lister
  • 45,515
  • 15
  • 108
  • 150
Exerosis
  • 33
  • 8
  • you need to get the value inside the attribute route? – Enmanuel Duran Sep 02 '16 at 22:12
  • @EnmanuelDurán Yep. – Exerosis Sep 02 '16 at 22:22
  • hmm... longtime since i used polymer -- Try adding a class eg (

    whatever

    ) and user Jquery (.each()) to get them. May work, but not sure - - check here how to get the values -- http://stackoverflow.com/questions/5292037/using-the-jquery-each-function-to-loop-through-classname-elements
    – Tasos Sep 02 '16 at 23:12
  • Yep its looks like its working -- https://jsfiddle.net/L6b77egu/ – Tasos Sep 02 '16 at 23:24

0 Answers0