Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion src/scripts/main.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
'use strict';

// write code here
const inputs = document.querySelectorAll('form input');

function capitalize(text) {
return text[0].toUpperCase() + text.slice(1);
}

inputs.forEach((input) => {
const label = document.createElement('label');
const capitalizedName = capitalize(input.name);

label.classList.add('field-label');
label.setAttribute('for', input.id);
label.textContent = capitalizedName;

input.placeholder = capitalizedName;
input.parentElement.append(label);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The .append() method adds the label as the last child of the parent element, which means it will appear after the input field in the HTML. The expected result image shows the label appearing above the input. To achieve this, consider using a method that adds the element at the beginning of the parent, such as .prepend().

});
Loading