by Ange Tuteur August 9th 2015, 7:36 pm
You can place as many functions as you want in a script. Everything usually gets combined into one file if the placement is "in all the pages"
Normally when writing JavaScript you'll want to execute it AFTER the desired HTML element is loaded ( or ready ). The JS codes management page executes all code in the <HEAD> section before the document is ready, so people usually start their scripts with a jQuery DOM ready function.
The basic and shortest syntax for that is :
- Code:
$(function() {
// everything else to execute when the DOM is ready
});
Where the comment is, is where you'll write your code.
Depending on what you're doing, you don't always need to use the above. It's mostly meant for if you're manipulating the document. ( e.g. add a specific function to an array of elements, or hiding something )
If it's just a normal function that will be called later, then you can just add it like this in JS management.
- Code:
function callMe() {
alert('You called me ?');
};