Solved

Jquery custom function not working

Posted on 2014-12-08
1
161 Views
Last Modified: 2014-12-08
I have created a custom jQuery function that if assigned a target it will display a timer countdown but it isn't working am i missing something.  Here is the code.  Also there would be a div called timer as well.

          $.fn.extend({
                gtime:function(min){
                    var usrminutes = 60 * min,
                            display = $(this),
                            mins, seconds;
                    setInterval(function() {
                        mins = parseInt(usrminutes / 60)
                        seconds = parseInt(usrminutes % 60);
                        seconds = (seconds < 10) ? "0" + seconds : seconds;
                        return $(this).html(mins + ":" + seconds);
                        usrminutes--;

                        if (usrminutes < 0) {
                            usrminutes = 60 * min;
                        }
                    }, 1000);


                }
            });

$('#timer').gtime(1);

Open in new window

0
Comment
Question by:stargateatlantis
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 58

Accepted Solution

by:
Gary earned 500 total points
ID: 40487371
          $.fn.extend({
                gtime:function(min){
                    var usrminutes = 60 * min,
                            display = $(this),
                            mins, seconds;
                    setInterval(function() {
                        mins = parseInt(usrminutes / 60)
                        seconds = parseInt(usrminutes % 60);
                        seconds = (seconds < 10) ? "0" + seconds : seconds;
                        display.html(mins + ":" + seconds);
                        usrminutes--;

                        if (usrminutes < 0) {
                            usrminutes = 60 * min;
                        }
                    }, 1000);


                }
            });

$('#timer').gtime(1);

Open in new window

0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction If you're like most people, you have occasionally made a typographical error when you're entering information into an online form.  And to your consternation, the browser remembers the error, and offers to autocomplete your future entr…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question