1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

"$jQuery(function($){" Question.....

Discussion in 'XenForo Development Discussions' started by HeadHodge, Mar 27, 2015.

  1. HeadHodge

    HeadHodge Member

    I'm unit testing my code before I include it in one of my templates.

    When I use the jQuery.document.ready function outside of xenforo, it works fine. But when I include it in a template it doesn't work.

    I've read that "nesting" document.ready is not possible. So does that mean document.ready is being handled before my template gets called, or should it work and I'm doing something wrong??

    Is there an easy way to test if the document is ready or not when it hits my template?

    The jQuery version that is being used by my xenforo install is "1.11.x";

  2. HeadHodge

    HeadHodge Member

    I thought I had tried this already, but tried again: $(document).ready(function($){
    and that seemed to work.

    Maybe a jQuery version issue with using $jQuery(function($){ ???
  3. Steve F

    Steve F Well-Known Member

  4. HeadHodge

    HeadHodge Member


    Since $ is synonymous to jQuery the above example can written as:
    // Shorthand for $( document ).ready()
    jQuery(function() {
    console.log( "ready!" );

    And the first parameter that is passed to the anonymous function is a reference to jQuery itself you can do this too:
    // Shorthand for $( document ).ready()
    jQuery(function($) {
    console.log( "ready!" );

    This is how I normally do it (i.e. jQuery(function($){) and that's what isn't working for me.
  5. HeadHodge

    HeadHodge Member

    Oh fudge..... I looked at my op and realized that I was trying to use "$jQuery(function($){", when it should be "jQuery(function($){". :(

    When I use the correct syntax, it works! doah...... :)
    tyteen4a03 and Steve F like this.
  6. tyteen4a03

    tyteen4a03 Well-Known Member

    Why do you want to nest document.ready in the first place? This event cannot be fired twice.
  7. HeadHodge

    HeadHodge Member

    Oh I don't.....
    I was just wondering if somehow xenforo was doing something that was blocking me from getting a ready event. My template is a subset of the main page, so I was thinking that might be causing my problem.

Share This Page