• I’m moving some code over to a plugin.

    The code uses jquery and has these lines in it:

        var hd = $$('day_header_'+idx);
        var bd = $$('day_body_'+idx);
        var toret = '';
        if(hd)
    	toret += hd.innerHTML;
        if(bd) {
    	if(toret)
    	    toret += '<br>';
    	toret += bd.innerHTML;
        }
    

    So basically it gets the values from the specified day_header and day_body items and combines them for display in a hover box.

    When I try this in WordPress (I’ve enqueued all the code with JQuerty as a prereq) I get the error

    Uncaught ReferenceError: $$ is not defined

    Have I missed something when I’ve been cutting the code over or does WP Jquery not use $$

    I’m on WordPress 5.7.2

    • This topic was modified 3 years, 10 months ago by Steve.
Viewing 2 replies - 1 through 2 (of 2 total)
  • Look carefully in the original code for a definition of $$. That is not part of jQuery. By default, jQuery uses $ to refer to the jQuery object, but in WordPress, jQuery is loaded in no-conflict mode, so even the $ is not defined.

    I usually have to wrap my jQuery code in a special function that binds $ to jQuery.

    See https://api.jquery.com/jquery.noconflict/

    Namely:

    (function( $ ) {
      $(function() {
        // More code using $ as alias to jQuery
      });
    })(jQuery);
    • This reply was modified 3 years, 10 months ago by Jack. Reason: make code snippet more succinct
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Jquery and $$’ is closed to new replies.