Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #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');
    #1320363

    Hey 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ünter

    #1320462

    so 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 ?

    #1320504

    Hi,

    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ünter

    #1320565

    thanks for clarification. Can be closed

    #1320587

    Hi,

    Have a great day.

    Best regards,
    Günter

Viewing 6 posts - 1 through 6 (of 6 total)
  • The topic ‘document ready ?’ is closed to new replies.