javascript - Backbone script executing before document fully loaded -
i building first rails app backbone , because of asset pipeline javascript getting called/executed before document loads. so, none of event handlers getting attached. if place javascript after html tags @ end of document, seems work fine. how can have code execute after page loaded? can use jquery's document.ready(), hoping backbone has inbuilt process deal it.
<script type="text/javascript"> (function() { "use strict"; var app; app = {}; app.appview = backbone.view.extend({ el: "body", initialize: function() { this.playaudio(); }, events: { "click .play-audio": "playaudio" }, playaudio: function() { alert($("span").data("audio")); } }); app.appview = new app.appview(); }).call(this); </script> <div> <p>whatever!</p><span class="glyphicon glyphicon-volume-up play-audio" data-audio="http://my-audio-file"></span> </div>
assign function document.onload or window.onload property. both same thing depends on browser.
<script> document.onload=(...your function goes here....) </script> //or <script> window.onload=(...your function goes here....) </script>
Comments
Post a Comment