This has been messing with my mind for quite a while: Can anyone explain what is the difference between 1 & 2?
(function($){...code...});
$(document).ready(function(){...code...});
I've always thought that they would be the same(except for the $ assignment which can be controlled in the first example), but it turns out that both present different behaviors.
In the following example the 'submit' code will work while the 'realtime validation' code wont :
<script >
(function($){
$('input, textarea, select, checkbox').each(function(){
... realtime validation code here ...
});
$('#subscribe_form').submit(function(){
... submit validation code here ...
});
})(jQuery);
</script>
In the following example the 'realtime validation' code will work while the 'submit' code wont :
<script>
$(document).ready(function(){
$('input, textarea, select, checkbox').each(function(){
... realtime validation code here ...
});
$('#subscribe_form').submit(function(){
... submit validation code here ...
});
});
</script>
What's going on here?