We can create function and use them as per requirment.
Executing on page load
<script>
$(document).ready(function() {
////////////////
my_function=function my_function(str){
$('#d1').html(str);
}
////////////
my_function('Welcome to Plus2net');
/////////////////
})
</script>
function executing on click
<input type=button id=b1 value='Show' onclick="my_function('hi')";>
<script>
$(document).ready(function() {
////////////////
my_function=function my_function(str){
$('#d1').html(str);
}
////////////
})
</script>
Calling User defined Function
<script>
$(document).ready(function() {
////////////////
my_function=function my_function(str){
$('#d1').html(str);
}
////////////
$('#b1').click(function(){
my_function('hi'); // calls another function
})
///////////
})
</script>
Returning Data from Function
<script>
$(document).ready(function() {
////////////////
my_function=function my_function(str){
return str+" I am plus2net ";
}
////////////
$('#b1').click(function(){
str = my_function('hi'); // calls another function
$('#d1').html(str);
})
})
</script>