What is the difference between these two functions?
1:
$(document).ready(function myfunc() {
function dosomething() {
// do something
}
});
2:
<script language="javascript">
function dosomething() {
// do something
}
</script>
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The
$(document).ready()function executes when the DOM has finished loading. See http://api.jquery.com/ready/Whereas the function is not executed until called. If you were to have a call to that function, it would happen as it is loading and not wait for any external event to complete as in the former. Like: