I have a simple Backbone.js page where in the view I am getting a div from the DOM and adding another div to it....
<body>
<div id="starbase"></div>
<script type="text/javascript">
(function($){
var ListView = Backbone.View.extend({
el: $("#starbase"),
initialize: function(){
_.bindAll(this, 'render');
this.render();
},
render: function(){
$(this.el).append('<div id="starship"></div>');
}
});
var listView = new ListView();
})(jQuery);
</script>
</body>
Is there any way I can force this render function to fire after jQuery DOM ready event has happened? Meaning the starship div should only get added to the starbase div after the jQuery ready has already happened.
#starbase
div, it'll only execute after it is created, in other words your scripts works the way you want ti – T J Mar 3 '16 at 12:43</body>
, which means all the DOM is ready. There is no practical difference in putting it inside a ready handler. If your<script>
was in say for example inside<head>
then DOM ready event will be useful – T J Mar 5 '16 at 5:38<script>
tag is at the end of<body>
tag, when your script runs, all the elements are already created and it'll work fine, so there is no need of jquery dom ready event – T J Mar 19 '16 at 4:18