Possible Duplicate:
jquery .bind() and/or .ready() not working
Why is there a difference in o/p between the below similar programs?
<html>
<head>
<script src="scripts/jquery-1.6.2.js"></script>
<script>
function main()
{
$("#inside").text("1234");
}
$(document).ready( function(){
main(); // 1
});
</script>
</head>
<body>
<div id="inside">abcd</div>
</body>
</html>
Output:1234
<html>
<head>
<script src="scripts/jquery-1.6.2.js"></script>
<script>
function main()
{
$("#inside").text("1234");
}
$(document).ready( main());//2
</script>
</head>
<body>
<div id="inside">
abcd
</div>
</body>
</html>
Output : abcd
Why does the innerHTML not change here? Kindly Explain this behavior.. 🙂
In the second variation, you’re calling
document.readyfor the result of the function. To call it for the function itself, just omit the parentheses: