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

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

HeadHodge

Active member
#1
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";

Thanks
 

HeadHodge

Active member
#2
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($){ ???
 

HeadHodge

Active member
#4
It would be
Code:
jQuery(document).ready(function($)
https://api.jquery.com/ready/
http://learn.jquery.com/using-jquery-core/document-ready/

jQuery Guide said:
Experienced developers sometimes use the shorthand $() for $( document ).ready(). If you are writing code that people who aren't experienced with jQuery may see, it's best to use the long form.

// Shorthand for $( document ).ready()
$(function() {
console.log( "ready!" );
});
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.
 

HeadHodge

Active member
#7
Why do you want to nest document.ready in the first place? This event cannot be fired twice.
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.