Is it necessary to use $(document).ready()
when using $().bind
??
HTML part:
<head>
<script type="text/javascript" src="jquery-1.10.2.min.js"></script>
<script type="text/javascript" src="test.js"></script>
<link rel="stylesheet" href="test.css" type="text/css">
</head>
<body>
<div style=''>
<input type="text" id="sendie" value="Type your reply here and press Enter" class="inputBox"/>
</div>
</body>
JS PART
$("#sendie").bind("click",function(){
console.log('log');
});
These are the two pieces of code I'm using to test. If I wrap the js part with $(document).ready
, it works fine though.
The reason I'm worried is that I will be doing a lot of keyboard + mouse bindings on different elements and if I have to write a $().ready all the time, it will be tedious(though I don't mind doing that but I am just curious ).
Is $(document).ready necessary?
I went through the above post and it says, $().ready
is not necessary if the ext js file is added before body tag, but I still can't do without it. Please help.
. $(document).ready is not necessary but for the bind to work the element should exist. So you have to execute the script after the element has been rendered.
– amit_g Nov 06 '13 at 18:45