functions inside or outside jquery document ready
        Posted  
        
            by Hans
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by Hans
        
        
        
        Published on 2010-04-15T12:52:11Z
        Indexed on 
            2010/04/15
            13:03 UTC
        
        
        Read the original article
        Hit count: 329
        
Up until now I just put all my jQuery goodness inside the $(document).ready() function, including simple functions used in certain user interactions. 
But functions that don´t require the DOM document to be loaded or are only called afterwards anyway, can be placed outside the $(document).ready() as well. Consider for example a very simple validation function such as:
function hexvalidate(color) {
// Validates 3-digit or 6-digit hex color codes 
 var reg = /^(#)?([0-9a-fA-F]{3})([0-9a-fA-F]{3})?$/;
 return reg.test(color);
}
The function is only called from within the  $(document).ready() function though.
What is best practice (syntax, speed); placing such a function inside or outside the jquery document ready function?
© Stack Overflow or respective owner