On 14 Apr., 15:41, MorningZ <morni...@gmail.com> wrote:
> So what is the error

The error is obviously that toDate is not a jQuery method. Another
problem is that that Dreamweaver method is using document.write which
can cause a problem depending on where the function is being called
and which is usually avoided in jQuery land.

Since toDate is not (yet) a jQuery method, let's make one:

(function($) {

    var days = [
        'Sunday',
        'Monday',
        'Tuesday',
        'Wednesday',
        'Thursday',
        'Friday',
        'Saturday'
    ];

    var months = [
        'January',
        'February',
        'March',
        'April',
        'May',
        'June',
        'July',
        'August',
        'September',
        'October',
        'November',
        'December'
    ];

    $.fn.toDate = function() {
        var now = new Date;
        return this.html('<p>Today\'s Date:<br />' + days[now.getDay
()] +
                        ', ' + now.getDate() + ' ' + months[now.getMonth()] + ' 
' +
                        now.getFullYear() + '</p>');
    };

})(jQuery);


Now you can use it like:

$(document).ready(function() {
   $('#today').toDate();
});


--Klaus

Reply via email to