document-ready

Why “$().ready(handler)” is not recommended?

冷暖自知 提交于 2019-11-26 07:25:52
问题 From the jQuery API docs site for ready All three of the following syntaxes are equivalent: $(document).ready(handler) $().ready(handler) (this is not recommended) $(handler) After doing homework - reading and playing with the source code, I have no idea why $().ready(handler) is not recommended. The first and third ways, are exactly the same, the third option calls the ready function on a cached jQuery object with document : rootjQuery = jQuery(document); ... ... // HANDLE: $(function) //

What is the difference between $(window).load and $(document).ready?

不羁的心 提交于 2019-11-26 05:45:33
问题 I have been having a problem lately with my JavaScript CODE and taking a portion of my code out of my $(document).ready() and putting it within $(window).load() fixed the problem. Now I understand that window.load is fired just after document.ready , but why is it not ready after document.ready , that is after window.load() ? 回答1: load is called when all assets are done loading, including images. ready is fired when the DOM is ready for interaction. From the MDC, window.onload : The load

How can I run a directive after the dom has finished rendering?

女生的网名这么多〃 提交于 2019-11-26 03:37:17
问题 I\'ve got a seemingly simple problem with no apparent (by reading the Angular JS docs) solution. I have got an Angular JS directive that does some calculations based on other DOM elements\' height to define the height of a container in the DOM. Something similar to this is going on inside the directive: return function(scope, element, attrs) { $(\'.main\').height( $(\'.site-header\').height() - $(\'.site-footer\').height() ); } The issue is that when the directive runs, $(\'site-header\')

$(document).ready shorthand

六眼飞鱼酱① 提交于 2019-11-26 03:32:38
问题 Is the following shorthand for $(document).ready ? (function($){ //some code })(jQuery); I see this pattern used a lot, but I\'m unable to find any reference to it. If it is shorthand for $(document).ready() , is there any particular reason it might not work? In my tests it seems to always fire before the ready event. 回答1: The shorthand for $(document).ready(handler) is $(handler) (where handler is a function). See here. The code in your question has nothing to do with .ready() . Rather, it

When should I use jQuery's document.ready function?

守給你的承諾、 提交于 2019-11-26 01:29:04
问题 I was told to use document.ready when I first started to use Javascript/jQuery but I never really learned why. Might someone provide some basic guidelines on when it makes sense to wrap javascript/jquery code inside jQuery\'s document.ready ? Some topics I\'m interested in: jQuery\'s .on() method: I use the .on() method for AJAX quite a bit (typically on dynamically created DOM elements). Should the .on() click handlers always be inside document.ready ? Performance: Is it more performant to

ng-repeat finish event

杀马特。学长 韩版系。学妹 提交于 2019-11-25 22:05:42
问题 I want to call some jQuery function targeting div with table. That table is populated with ng-repeat . When I call it on $(document).ready() I have no result. Also $scope.$on(\'$viewContentLoaded\', myFunc); doesn\'t help. Is there any way to execute function right after ng-repeat population completes? I\'ve read an advice about using custom directive , but I have no clue how to use it with ng-repeat and my div... 回答1: Indeed, you should use directives, and there is no event tied to the end