Make WordPress Core

Changes between Version 1 and Version 2 of Ticket #45130, comment 2


Ignore:
Timestamp:
10/23/2018 07:22:02 AM (5 years ago)
Author:
remzicavdar
Comment:

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #45130, comment 2

    v1 v2  
    2020
    2121
    22 It is also good practice to put all the scripts into the footer, I understand that this has been discussed before. Even when the team decides not to, it's best to use document ready, otherwise everything breaks if jQuery has been placed in the footer. If a theme developer decides to put jQuery in the footer in his or her theme. In this case, we would preface the anonymous function with a document ready function as seen below:
     22It is also good practice to put all the scripts into the footer, I understand that this has been discussed before. Even when the team decides not to, it's best to use document ready, otherwise everything breaks if jQuery has been placed in the footer. If a theme developer decides to put jQuery in the footer in his or her theme. In this case, we would preface the function with a document ready function as seen below:
    2323
    2424{{{
    2525jQuery(document).ready(function($) {
    26    // Your jQuery code
     26   // $ Works! You can test it with next line if you like
     27   // console.log($);
    2728});
    2829}}}
     
    3031I think using document ready is always a good thing to do, even if you put your code in the header.
    3132
     33
     34This is also possible, but it will defeat the purpose of using jQuery noConflict mode:
     35
     36{{{
     37var $ = jQuery.noConflict();
     38
     39$( ".whatever" ).hide();
     40}}}