Code explanation:

It is simple. If you know C programming, javascript and something about web.

You have three different buttons, 3 different ids for each.

id is an attribute of a HTML DOM object or node.

Each of the buttons have an identifier. There can only be one id in one page.

You cannot repeat the same id in a page.

Now you register click() handlers for each of the buttons. We want the
buttons to
 do something for us. That is why they are there.

That is done with this code.

$(selector).click(function() {

           BODY

});

So here you can specify that when you click on the particular id or
button the BODY will be executed.

That is what I use to do the counting.

And setInterval() and setTimeout() are two basic javascript functions
used in all animations.

-Girish

On Sun, Jun 16, 2013 at 11:58 AM, Girish Venkatachalam
<[email protected]> wrote:
> Do more and more coding.Less and less talking.
>
> Talking will not feed you. Coding and experience will.
>
> I will be really happy if you ask me technical questions.
>
> I tried your code, your style sucks, your explanation is not
>  adequate, this is wrong, you can add this etc.
>
> But I think LUG will become like that when I am 80 years old.
>
> We will now look at how to do a simple counter using jQuery.
>
> Counting can be done in many many ways.
>
> I am illustrating one such.
>
> Code:
>
> var cnt = 0;
> function counting() {
>         cnt++;
>         if(cnt == 10000) {
>                 cnt = 0;
>         }
>         $('p').text(cnt);
> }
>
> $(function() {
>         $('h1').fadeOut(6000);
>         tmr = setInterval("counting()", 200);
>         $('#stop').click(function() {
>                 clearInterval(tmr);
>                 $('p').text('stopped');
>         });
>         $('#start').click(function() {
>                 tmr = setInterval("counting()", 200);
>         });
>         $('#reset').click(function() {
>                 cnt = 0;
>         });
> })
>
> Data:
>
>  <h1> Hi there this will vanish </h1>
>
>         <p> </p>
>         <input id='stop' type="button" value="Stop counting" />
>         <input id='start'  type="button" value="Start counting" />
>         <input id='reset'  type="button" value="Reset counter" />
>
> Result?
>
> http://awrdev.g3tech.in/
>
> --
> Gayatri Hitech
> http://gayatri-hitech.com



-- 
Gayatri Hitech
http://gayatri-hitech.com
_______________________________________________
ILUGC Mailing List:
http://www.ae.iitm.ac.in/mailman/listinfo/ilugc
ILUGC Mailing List Guidelines:
http://ilugc.in/mailinglist-guidelines

Reply via email to