create a button in javascript

To create a button in JavaScript, you can use the createElement method to make a button element and then add it to the DOM. Here's an example:

index.tsx
// create a button element
const button = document.createElement('button');
// set the button text
button.textContent = 'Click me!';
// add an event listener
button.addEventListener('click', () => {
  console.log('Button clicked!');
});
// add the button to the DOM
document.body.appendChild(button);
301 chars
11 lines

This code creates a button element, sets the button text, adds an event listener to the button, and finally appends the button to the body of the HTML document. When the button is clicked, it will log a message to the console.

gistlibby LogSnag