I have a page with lots of jquery. There are lots of functions inside:
$( document ).ready(function() {
//lots of functions
});
After that "document ready" snippet closes, I have a function written like this:
$(function(){
$('#number-of-coins input[type=radio]').change(function () {
var numcoins=$("input[name=numbercoins]:checked").val();
if (numcoins == "2") {
$( "p.two" ).show();
$( "p.three" ).hide();
} else if (numcoins == "3") {
$( "p.two" ).hide();
$( "p.three" ).show();
} else {
$( "p.two" ).hide();
$( "p.three" ).hide();
}
});
});
What this does is not important, but it does work properly. My question is, would it be more efficient to take this section below (without the "function" wrapper) and move it into the "document ready" snippet? Or does it not matter either way? I did that as a test and it worked, so it would seem to me that every function should just go inside of the "document ready" snippet, since it's slightly less code not having to write the function wrapper each time. Is that accurate or does it depend?
$('#number-of-coins input[type=radio]').change(function () {
var numcoins=$("input[name=numbercoins]:checked").val();
if (numcoins == "2") {
$( "p.two" ).show();
$( "p.three" ).hide();
} else if (numcoins == "3") {
$( "p.two" ).hide();
$( "p.three" ).show();
} else {
$( "p.two" ).hide();
$( "p.three" ).hide();
}
});