WordPress.org

Make WordPress Core

Changes between Initial Version and Version 1 of Ticket #45130, comment 6


Ignore:
Timestamp:
10/24/2018 05:14:08 PM (2 years ago)
Author:
remzicavdar
Comment:

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #45130, comment 6

    initial v1  
    11Okay, thanks for your reply. What do you suggest we should do?
    22Do a document ready on every script or something else. I'm just a junior web dev and I know WordPress, but not really in depth or each component.
     3
     4
     5Edit: I know WordPress is using an older version of jQuery for compatibility reasons, but document ready is deprecated as of jQuery 1.8 and removed in jQuery 3.0. See link: [https://api.jquery.com/ready/]
     6
     7**Before and as of jQuery 3.0 ineffective:**
     8{{{
     9$( document ).ready(function() {
     10  // Handler for .ready() called.
     11});
     12}}}
     13
     14**Which is equivalent to:**
     15{{{
     16$(function() {
     17  // Handler for .ready() called.
     18});
     19}}}
     20
     21Which is problematic for WordPress, when $.noConflict() is used to avoid conflicts the $ shortcut is no longer available. However, we could still pass a reference to the jQuery object. This allows us to use the jQuery object with a dollar sign $, like this:
     22
     23
     24{{{
     25WordPress = jQuery.noConflict();
     26
     27WordPress(function( $ ) {
     28  // Code using $ as usual goes here; the actual jQuery object is jq2
     29});
     30}}}
     31