Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 188897
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T16:07:37+00:00 2026-05-11T16:07:37+00:00

I am making a very minimalistic calendar plugin for the website with jQuery. I

  • 0

I am making a very minimalistic calendar plugin for the website with jQuery. I have not had much expirience with it, so I was following plugin tutorial. I have two <a> links that should change month, but unfortunately they do so only once and then both of them stop working. I suspect I have put events to a wrong place.

Sorry for quite messy code it is just a blueprint yet.

Here is the javascript.

(function($){    
    $.fn.extend({
        jSimpleCalendar : function(currentDate)
        {


            return this.each(
                function()
                {               

                    obj = $(this);

                    result = renderCalendar(currentDate);   

                    obj.html(result);

                                        // Event handlers
                    $('#JQSCMonthPrev').click(function ()
                    {
                        currentDate.setMonth(currentDate.getMonth() - 1);
                        result = renderCalendar(currentDate);

                        obj.html(result);

                    });
                                        $('#JQSCMonthNext').click(function ()
                    {
                        currentDate.setMonth(currentDate.getMonth() + 1);
                        result = renderCalendar(currentDate);

                        obj.html(result);

                    });

                });



            function renderCalendar(date)
            {
                // Get the calendar
                calendar = createMonthArray(date);

                // Build xhtml
                var result = '<table class="jQSCTable">';               

                result += '<thead><tr><td colspan=4><a href="#" id="JQSCMonthPrev">&lt;</a> <a href="">' + getMonthNames()[date.getMonth()] + '</a> <a href="#" id="JQSCMonthNext">&gt;</a></td>';
                result += '<td colspan=3><a href="#" id="JQSCYearPrev">&lt;</a> <a href="">' + date.getFullYear() + '</a> <a href="#" id="JQSCYearNext" >&gt;</a></td></tr></thead><tbody>';


                for(i=0;i<(calendar.length);i++)
                {
                    result += '<tr>';
                    for (a=1; a<=7; a++)
                    {
                        result += '<td>';
                        if(calendar[i][a]!='N')
                        {
                            result += '<a id="JQSCLink' + calendar[i][a] + '">' + calendar[i][a] + '</a>';
                        }
                        result += '</td>';
                    }
                    result += '</tr>';
                }
                result += '</tbody></table>';   

                return result;          

            };  

            function createMonthArray(date)
            {
                // Get first day of month
                date.setDate(1);

                // Make callendar
                var calendar = new Array();

                // Fill empty shit from previous month
                for(i=0;i<date.getDay()-1;i++)
                    calendar.push('N');

                // Get number of days
                var numberOfDays = getNumberOfDaysMonth(date);

                //Fill the rest
                for(i=1;i<numberOfDays+1;i++)
                    calendar.push(i);               

                // Get number of end days
                var endDays = calendar.length % 7 - 1;

                //Fill the empty stuff at the end
                for(i=0;i<7-endDays;i++)
                    calendar.push('N');         



                //Slice to seven pieces
                var slicedCalendar = new Array();
                var week = 0;
                slicedCalendar[0] = new Array();
                for(i=1;i<calendar.length;i++)
                {
                    slicedCalendar[week][i-week*7] = calendar[i-1];
                    if (((i%7)==0)&&(i!=0))
                    {
                        week++;
                        slicedCalendar[week] = new Array();
                    }
                }
                return slicedCalendar.splice(0, week);

            };      

            function getNumberOfDaysMonth(date)
            {
                var minDays = 28;
                var dateFound = false;          
                var oldMonth = date.getMonth();
                var workDate = new Date(date.getYear(), date.getMonth(), 1);

                while (!dateFound)
                {
                    workDate.setDate(minDays+1);                
                    var newMonth = workDate.getMonth();//new month date 

                    if (newMonth != oldMonth)//if the month has changed
                        dateFound = true;
                    else
                        minDays++;
                }

                return minDays;         

            }   

            // Month names
            function getMonthNames()    
            {
                var month = Array();
                month[0] = 'January';
                month[1] = 'February';
                month[2] = 'March';
                month[3] = 'April';
                month[4] = 'May';
                month[5] = 'June';
                month[6] = 'July';
                month[7] = 'August';
                month[8] = 'September';
                month[9] = 'Octorber';
                month[10] = 'November';
                month[11] = 'December';

                return month;
            }       

        }
    });         
})(jQuery);

Here is html test.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <script type="text/javascript" src="js/jquery-1.3.2.min.js"></script>
        <script type="text/javascript" src="js/jSimpleCalendar.js"></script>
        <script type="text/javascript">
            $(document).ready(function(){
                $("#calendar").jSimpleCalendar(new Date());
            });
        </script>
    </head>
    <body>
        <div id="calendar">
        </div>      
    </body>
</html>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-11T16:07:37+00:00Added an answer on May 11, 2026 at 4:07 pm

    Seems like what’s happening is the HTML is being rewritten when you click the first time. When this happens, the click events are no longer bound to the hrefs since the older elements were removed from the DOM.

    You could put the click events into it’s own function and call the function after rebuilding the calendar or use event delegation. For this, append the click event on the #calendar div and track which element was clicked.

    http://www.learningjquery.com/2008/03/working-with-events-part-1

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am making a very simple datatable with JSF 2.0 tag dataTable but for
I was recently making a very simple application that just printed matrix-effect out to
I'm making a very simple turn based battle game using ActionScript 2.0. I'm VERY
Given: A table named TABLE_1 with the following columns: ID ColumnA ColumnB ColumnC I
I'm building a photo book layout application. The application frequently decompresses JPEG images into
I am creating a selenium test and in all the tests I want to
Without in-depth analysis of the source code, is it possible to make an informed
We've got an EF model that's using POCO generation for its types. We added
For a system I'm working on I've got a bit of a problem: I'm
Recently my university has set large projects for its undergraduates. One of these projects

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.