Solved

Jquery custom function not working

Posted on 2014-12-08
1
148 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
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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Suggested Solutions

Requirements JQuery 1.6+ HTML CSS Introduction This article was inspired by an EE question (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28372511.html) on how to make a page show some balloons animate up a page…
In this article you'll learn how to use Ajax calls within your CodeIgniter application. To explain this, I'll illustrate how to implement a simple contact form to allow visitors to send you an email through your web site.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. 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.: (CODE)
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…

747 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now