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');
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
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 ?
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
thanks for clarification. Can be closed