On Apr 22, 5:29 pm, James <james.gp....@gmail.com> wrote:
> Something like the below?
>
> (function($) {
>                   $.fn.JSClock = function() {
>                           setInterval(function() {
>                                // code to get and write time here
>                           }, 1000);
>                    }
> > })(jQuery);

In and of themselves the above and the following both fail. My guess
is that this.html() object is not a proper reference.  I say this,
because the code JSClock() does not interfere with the rest of my
jQuery methods when placed inside the $.ready( ) method.

(function($) {
        $.fn.JSClock = function() {
                function timeFormat(i) {
                        if (i < 10) {
                                i="0" + i;
                        }
                return i;
                }
                setInterval(function() {
                        var today=new Date();
                        var h=today.getHours();
                        var m=today.getMinutes();
                        var s=today.getSeconds();
                        m=timeFormat(m);
                        s=timeFormat(s);
                        this.html("Local Time: " + h +":"+ m +":"+s);
                },500);
        }
})(jQuery);

$(document).ready(function() {
        $('#flowers').writeColorOfFlower();
        $('#today').toDate();
        $('#clock').JSClock();
});

Reply via email to