MCPcopy Create free account
hub / github.com/LinkedInLearning/javascript-essential-training-2832077 / newStrapLength

Function newStrapLength

10_01/script.js:40–76  ·  view source on GitHub ↗
(strapArray)

Source from the content-addressed store, hash-verified

38 * Strap length functionality
39 */
40const newStrapLength = (strapArray) => {
41 console.log(strapArray);
42 // Loop through each element on the list
43 strapArray.forEach((listElement) => {
44 // Get what side we are working with
45 let side = listElement.getAttribute("data-side");
46 console.log(side);
47
48 // Create a new form element
49 const lengthForm = document.createElement("form");
50 lengthForm.classList.add(`${side}length`);
51
52 // Populate form with an input and a button
53 lengthForm.innerHTML = `
54 <input type="number" name="${side}Length" placeholder="New ${side} length">
55 <button>Update</button>
56 `;
57
58 // Add event listener to the form submit action
59 lengthForm.addEventListener("submit", (e) => {
60 // Stop form from reloading the page
61 e.preventDefault();
62
63 // Get the value from the form input
64 let newValue = lengthForm.querySelector("input").value;
65
66 // Set the value of the field
67 listElement.querySelector("span").innerHTML = `${newValue} inches`;
68
69 // Clear the form input
70 lengthForm.querySelector("input").value = "";
71 });
72
73 // Add form to the end of the list element
74 listElement.append(lengthForm);
75 });
76};
77
78const backpackList = backpackObjectArray.map((backpack) => {
79 let backpackArticle = document.createElement("article");

Callers 1

script.jsFile · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected