develop a chronological record for each task completed using JavaScript

Click the button to display the current date, then click again to show the current date in a new line. This will create a timelog displayed in a table format, with each time appearing in a separate box within the table.

The code function for getting the date is as follows:

Button.addEventListener("click", function Click() {
  document.getElementById("pergraph").innerHTML = Date(); } 

I am unable to simply use "/n"...

Thank you.

Answer №1

Embedding content using the += operator rather than replacing it with the = operator:

Button.addEventListener("click", function Click() {
  document.getElementById("pergraph").innerHTML += Date() + "<br>";
})
<button id="Button" type="button">
Add date
</button>

<p id="pergraph">

</p>

If you prefer to have separate, stylable elements, enclose the date in a span and apply CSS styling:

Button.addEventListener("click", function Click() {
  document.getElementById("pergraph").innerHTML += "<span>" + Date() + "</span>";
})
#pergraph span {
  display: block;
  background: #f2f2f2;
  margin-bottom: 4px;
  padding: 4px;
}
<button id="Button" type="button">
Add date
</button>

<p id="pergraph">

</p>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Send a POST request and handle the response in a Node.js environment using EJS

Currently, I am working on an Index Site (EJS) where I have implemented a select form that reads an array. In my index.ejs file, the code looks like this: <html> <head> </head> <body> <center> <fo ...

Emails sent through an HTML form submission should always include a valid "from"

I am currently in the process of creating a feedback form that allows individuals to provide anonymous feedback. I have explored nodemailer and node-sendmail, but I have encountered an issue with both requiring a from address. While I am aware that this ca ...

What is the process for adding content to a textarea field?

Is there a way to dynamically update a textarea using PHP and trigger the refresh of the textarea? APPRECIATE IT Edit: The solution should be initiated by server-side PHP code ...

Building a Strong Friendship Between Nuxt-auth and Nuxt-i18n

I am facing a challenge while trying to integrate the nuxt@auth module and nuxt-i18n together. The issue arises when I need to have different routes for the login page based on language. For instance: pages: { login: { en: '/authentication', ...

The element's height appears to be fluctuating unexpectedly when I attempt to adjust it using percentage values within a narrow range

I'm utilizing React and Bootstrap in this project. Here's an overview of my code: I have an element with height set to 0, in rem. My goal is to make the height of this element increase as I scroll down the page, creating the illusion that it is ...

Error message: "jQuery is not defined and occurs exclusively in Chrome."

I've been using the following code to asynchronously load my JavaScript in the head section: <script type='text/javascript'> // Add a script element as a child of the body function downloadJSAtOnload() { var element4= document.creat ...

Having trouble getting Vue to properly focus on an input field

I am attempting to use this.$refs.cInput.focus() (cInput being a ref) but it seems to not be functioning as expected. I expect that when I press the 'g' key, the input field should appear and the cursor should immediately focus on it, allowing me ...

Can you show me a way to smoothly fade out a selected element upon clicking with jQuery?

I am currently working on a jQuery function that will fade out a specific element when the user clicks on it within the webpage. Initially, I attempted to use the universal selector to target all elements, but this resulted in every element on the page fa ...

Error in TMDb API: JSON data abruptly ended

Currently, I am attempting to parse JSON data that is being returned by The Movie DB. Unfortunately, I keep encountering an error message indicating the following: Uncaught SyntaxError: Unexpected end of JSON input at JSON.parse (<anonymous>) ...

What is the reason behind Angular (1.x) permitting a module's dependency to directly reference its components?

Take a look at this code snippet: angular.module('app', ['app.core']) .factory('NameService', function() { return { getName: function() { return 'Omar' ;} }; }); angula ...

"Ng-repeat function seems to be malfunctioning, although I am able to view

There seems to be an issue with ng-repeat when dealing with an array of objects: dummy.json [ {"name":"alpha", "data":[{"name":"Unit 1", "prereqs":[]}]}, {"name":"beta", "data":[{"name":"Unit 1", "prereqs":[]}]} ] While I am able to fetch the total ...

Conceal the name of a property when displaying it

I have a function that retrieves data from an interface, which includes a property called name. Currently, the output includes the property name, but I would like to remove it if possible. How can I achieve this? Here is the interface structure: export i ...

Vue's v-on:click feature stops functioning correctly post-build

I have successfully integrated the Vue slide example from this link into my Angular template. Everything works fine when running ng serve, but after building with ng build and then trying to start it again with ng serve or from the dist folder using npm s ...

In React components, encountering "cannot read properties of undefined" error occurs, whereas it functions perfectly fine within the getStaticProps

I am currently in the process of setting up a blog using Node.js, React, and graphql. Despite being new to these technologies, including Java and Typescript, I am seeking assistance from anyone who may be able to help. My current roadblock involves display ...

Error: props.addPost does not exist as a function

Help Needed with React Error: props.addPost is not a function. I am trying to add a new post in my app. Please assist me. import React from "react"; import classes from "./MyPosts.module.css"; import { Post } from "./Post/Post.jsx& ...

The printing function for the window system can cause disruptions to the layout of the table

After creating a page with a simple table that can be filled in and printed, I noticed some issues with the table formatting after printing. The intended table design was supposed to look like this: https://i.stack.imgur.com/aAk89.png However, upon print ...

Substituting Hebrew characters for Mandaic characters within certain HTML tags can cause links to malfunction

What causes the JavaScript code provided to replace Mandaic characters with Hebrew characters on a webpage to also disable all links on the page? The code snippet is as shown below: function replaceMandaicCharacters() { const mandaicLetters = "&bsol ...

Tips for modifying the style of a component within node_modules using its individual vue <style> sections

I am trying to modify the CSS file within the multiselect package, but I don't want to make changes directly in the node_modules folder. Instead, I want to add my custom styles between the style tags of my Vue page. Specifically, I am attempting to ad ...

What is the best way to have an input automatically update its value to match its ID?

Can someone assist me with creating a button to display answers to questions using input boxes? I have assigned the IDs of the input boxes as the answers themselves, but I am facing issues trying to change the text to match their respective IDs. The curr ...

The array starts off with no elements, but once information is entered into a text field for filtering, it becomes populated

I am transferring an array from one component to another component. The initial array is populated by a database and is not empty. However, when I try to iterate over the array in my second component, it shows up as empty with length = 0. Strangely, afte ...