I am not sure when we use $(document).ready(function() { });
and when we can declare a $(function() { }
without it being declared in the $(document).ready(function() { });
For example the following snippet:
<body>
<textarea id="test" cols="50" rows="15"><p><h3>Test H3</h3>This is some sample text to test out the <b>WYSIWYG Control</b>.</p></textarea>
<script type="text/javascript">
$(function() {
$("textarea").htmlarea();
});
</script>
works without using the $(document).ready(function() { });
but the following:
<body>
<textarea id="test" cols="50" rows="15"><p><h3>Test H3</h3>This is some sample text to test out the <b>WYSIWYG Control</b>.</p></textarea>
<script type="text/javascript">
$(document).ready(function(){
$("btn").click(function(){
alert('Hello!!!');
});
});
$(function() {
$("textarea").htmlarea();
});
</script>
When I press the button with id="btn"
, it does nothing.
Am I doing this wrong?