INNER CODE UNIT · JavaScript

addTodo

Bharat2044/100xDevs-Cohort3-WebDev-and-Devops · Week 03 - DOM/3.1 - DOM Simple/Assignment Solution/Assignment 1 Solution/index.js:6

function addTodo() {
    // Get the input element and store it in a variable called input
    const input = document.querySelector("input");

    // get the value of the input element and store it in a variable called value
    const value = input.value;

    // Check if the value is not empty or only whitespace characters 
    if (value.trim()) {
        // Create a new div element and store it in a variable called element
        const element = document.createElement("div");

        // Set the inner text of the element to the value
        element.innerText = value;

        // Append the element to the body of the document 
        document.querySelector("body").appendChild(element);
    } else { 

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…