skip to Main Content

I am attempting to create a Calender using Jquery. But I don’t understand how to have my object print the value it contains. I tried JSON.toString() on my table data but it did not correct my issue. Maybe I am misplacing the toString method in my code?

Before toString:

// get the number of days in the month
let daysInMonth = new Date(this.displayDate.getFullYear(), this.displayDate.getMonth() + 1, 0).getDate();

// get array of days to display
let days = [];
for (let i = 1; i <= daysInMonth; i++) {
  days.push(new Date(displayDate.getFullYear(), displayDate.getMonth(),i));
}

 console.log(this.monthNames[this.displayDate.getMonth()] + " " + this.displayDate.getFullYear());

td = $("<td>").attr("class", "day").text(days[i].getDate());
td.append(td);

Based on this Firefox Javascript guide [object, object] is corrected using the JSON.toString() method. But when I implemented it

      td = $("<td>").attr("class", "day").text(days[i].getDate());
      td.append(JSON.stringify("td"));

JSFiddle is here.

2

Answers


  1. You add wrong variable to method .text().

    In this code: you must add days[i].getDate() not elem

    change td= $("<th>").text(elem); => td= $("<th>").text(days[i].getDate());

    let monthDay = $('<monthDay>');
    let textNode = $(days[i].getDate());
    td = $("<td>");
    
    td= $("<th>").text(days[i].getDate());  <--- like this
    tr.append(td);
    
    Login or Signup to reply.
  2. Line 133 : let textNode = $(days[i].getDate());

    $(days[i].getDate()); is an object, days[i].getDate(); is a int and you want this int.

    Then you can use your textNode

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search