Jquery ready dom
i got a kind of issue of JQuery ( i started few times ago), i have a very BIG html page, and i have a widget at the start of this page, but i did a document.ready so it's waiting that all my 开发者_如何学JAVApage is loaded before to execute which is too long.
So how i can execute jquery just after my widget is loaded ? i tried something like $(myWidget).ready() but it's not working
I hope i'm clear enough
CHeers
If you take a look at the documentation of jQuery :
$(function () {
// Everything here will be called AFTER the DOM is loaded
// So it will be called after your widget is loaded
// but it will wait that your whole page is loaded.
});
But now, if you want the Javascript code to be executed just after the widget is ready and not waiting that the whole page is loaded, the only (proper) way I know is to create the widget via Javascript with some DOM manipulation. And doing so, you could use the code given by @Robbert.
Then, if you don't mind having a bad code, you can do the javscript just after the HTML widget, but this is awfully wrong and I don't recommend you to do that.
<div class="widget">
<!-- Your widget html code -->
</div>
<script>
// your JS code
</script>
Based on the three solution given, I would recommend you to generate the Widget directly from javascript. It's better, not intrusive and you don't have to wait that the whole page is loaded.
You could just add your javascript after that widget and don't have a load event
Try something like
widget_function()
$(document).ready(
other JS
)
just do the widget outside the document.ready then it wil load before your html
精彩评论