Basically, what this snippet does, is

1/ adding a DIV element at the end of the BODY element;
2/ counting the new amount of DIV
3/ printing the string "there are XX dvis" in every SPAN element
available in the DOM
4/ triggering the onclick() event so the script runs once on page ready.

So the whole script actually runs whenever the document is ready, and
then every time someone clicks on the body.


On Tue, Jan 6, 2009 at 5:05 PM, Andy <adharb...@gmail.com> wrote:
>
> I'm trying to figure out how this works.  It appears it is re-
> iterating the click function in this call.  Why would this work?  I
> don't see how I would know to create the method this way if I was
> going to recreate this.
>
>  $(document).ready(function(){
>
>         $(document.body).click(function () {
>             $(document.body).append($("<div>"));
>                 var n = $("div").size();
>                 $("span").text("There are " + n + " divs." + "Click to add
> more.");
>              }).click(); // trigger the click to start
>                 });
>

Reply via email to