Jquery selector not working with element inside script tag using Cassette

When I try to access data loading using, $("#index").data("onload")I return 'undefined':

<script type="text/html">
        <section id="index" data-onload="app.load()">
            <div data-bind="text:name"></div>
        </section>
</script>

Without a script environment, everything works fine. This is loaded using Cassette , which wraps it in script tags.

What am I doing wrong?

+3
source share
3 answers

The contents of the script tag is not part of the DOM tree for your document. If you think about it, this makes sense, because the JavaScript syntax is not valid HTML, and you can just drag and drop JavaScript between script tags.

, HTML script. JavaScript data-onload script, script.

, HTML , , MVC. , script type = "text/html", . #index , DOM. HTML , JQuery.

+6

Script , , .
, /html- script.

:

    <section id="index" data-onload="YourTextValue">
        <div data-bind="YourTextValue"></div>
    </section>
0

As far as I know, the code inside the tag <script>is usually compiled as Javascript and is not part of the DOM. And I'm not sure if <script type="text/html">- even a valid combination of tags / attributes.

Remove the script tag, you do not need it.

-1
source

All Articles