I’m creating a calendar using JavaScript, and encountered an issue with spacing out my "previous" and "next" arrow keys. Currently one sits on top of the other on the left side of the calendar, whereas I need them on either ends of the calendar. I’m only learning and I cannot see what I did wrong.
This is a piece of my code regarding the setting up of the calendar and the buttons. I’m supposed to be using jQuery too!
//Generate tabular calendar
var table = $("<table>");
var tableRow = $("<tr>");
var tableCell = $("<td>");
// Create a Button
var prevMonth = $("<button>");
prevMonth.attr("value","Previous Month").text("<<");
prevMonth.click(function() { // Function for clicking previous month button
cal.display(new Date(displayDate.getFullYear(), (displayDate.getMonth() - 1)));
});
tableCell.append(prevMonth);
tableRow.append(tableCell);
let tableCellColSpan = $("<td>"); // Spacing out the nav buttons
tableCellColSpan.attr("colspan","5"); // I think the issue is here somewhere
tableCell.append(tableCellColSpan);
// Create Button + Button Event Handler
nextMonth = $("<button>");
nextMonth.attr("value","Next Month").text(">>");
nextMonth.click(nextNav);
function nextNav() { // Function for clicking next month button
cal.display(new Date(displayDate.getFullYear(), (displayDate.getMonth() + 1)));
};
tableCell.append(nextMonth);
tableRow.append(tableCell);
table.append(tableRow);
2
Answers
One easy way is just give each button a class. Then have the previous button float left and the next button float right.
Your problem is more CSS than JavaScript, If you seek help with JavaScript, post the code that defines the method
display()
as well as a link to the documentation of the plugin you are using.<thead>
add an empty<th>
to the beginning and to the end of<tr>
<tbody>
add an empty<td>
to the beginning and to the end of the first<tr>
rowspan=5
to the first<td>
and to the last<td>
of<tbody>
<button>
to each<td rowspan=5>
The following example is a CSS sokution.