what is a basic html page in javascript

Here's an example of a basic HTML page created dynamically using JavaScript:

index.tsx
// Create a new HTML page
const htmlPage = document.createElement('html');

// Add a head section to the page
const headSection = document.createElement('head');
const titleElement = document.createElement('title');
const titleText = document.createTextNode("My Title");
titleElement.appendChild(titleText);
headSection.appendChild(titleElement);
htmlPage.appendChild(headSection);

// Add a body section to the page
const bodySection = document.createElement('body');
const headerElement = document.createElement('h1');
const headerText = document.createTextNode("Welcome to my page!");
headerElement.appendChild(headerText);
bodySection.appendChild(headerElement);
htmlPage.appendChild(bodySection);

// Add the new page to the DOM
document.appendChild(htmlPage);
766 chars
22 lines

This JavaScript code creates a new HTML page with a head section containing a title element and a body section containing a header element, both with some text. Finally, the new page is added to the DOM. You can run this code in the console of your browser to see the result.

gistlibby LogSnag