I saw somewhere some jquery code on the net that took this form:
<script> function doSomething(message) { $(document).ready(function(){ alert(message); }); }; </script>
i.e. an external function ("doSomething") that has $ (document) .ready inside it. I got confused because this is not the code under $ (document) .ready called when loading the DOM? This is similar to an event handler inside a function (?). Does this form of code make sense to everyone? Thank.
, . , doSomething . : DOM , ready, jQuery , , , - doSomething. , , — , , , : -) — .
doSomething
ready
. $(document).ready , , DOM . , , - . DOM, .
Javascript DOM, , , , DOM. , , DOM.
?
, .
$().ready(); , , DOM . . , .ready(), doSomething();
:
<script type="text/javascript"> function doSomething(){ $(document).ready(function(){ alert('here'); }); } doSomething(); </script>
Put this in different parts of your HTML and check it (:
Hooray!