-
AuthorPosts
-
September 10, 2021 at 9:36 am #1320355
on upcomming fixes i read about :
compatibility update: jQuery 3.0 ( replace deprecated $( document ).ready( handler ) )
what is the usage now? only
$(function() {and does that indicate directly that a jQuery Usage is done ?
all my jQuery snippets til now use:function my_custom_script() { ?> <script> (function($){ // … here with only $ instead of jQuery })(jQuery); </script> <?php } add_action('wp_footer', 'my_custom_script');do i have to use it now this way if i want to wait til DOM is ready ?
function my_custom_script() { ?> <script> (function($){ $(function() { // $ code to manipulate DOM goes here }); })(jQuery); </script> <?php } add_action('wp_footer', 'my_custom_script');September 10, 2021 at 10:41 am #1320363Hey Guenter,
If you check https://api.jquery.com/ready/
$(function() {is enough as long as you do not need “Aliasing the jQuery Object”.
(function($){ ..... })(jQuery);is used to encapsule the code section from other js code (= like code in a function in php) to avoid name conflict.
Best regards,
GünterSeptember 10, 2021 at 8:41 pm #1320462so in Combination i had to use:
function my_custom_script() { ?> <script> (function($){ $(function() { // $ code to manipulate DOM goes here }); })(jQuery); </script> <?php } add_action('wp_footer', 'my_custom_script');or does the usage of
$(function() {indicate the usage of $ instead of jQuery.and DOM is ready then to be manipulated ?
September 11, 2021 at 11:52 am #1320504Hi,
Yes, this frame above allows to use $ for jQuery in “code to manipulate DOM goes here” and is executed when DOM is ready.
(function($){ var i,j,k; $(function() { // $ code to manipulate DOM goes here }); })(jQuery);Variables i,j,k can be accessed from inside “code to manipulate DOM goes here” but are invisible from outside the frame.
Best regards,
GünterSeptember 12, 2021 at 9:27 am #1320565thanks for clarification. Can be closed
September 12, 2021 at 4:45 pm #1320587 -
AuthorPosts
- The topic ‘document ready ?’ is closed to new replies.
