Skip to content
Open
Changes from all commits
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
28 changes: 27 additions & 1 deletion src/scripts/main.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,29 @@
'use strict';

// write code here
// Select all forms on the page
const forms = document.querySelectorAll('form');

forms.forEach((form) => {
const inputs = form.querySelectorAll('input');

inputs.forEach((input) => {
// Create label
const label = document.createElement('label');

label.className = 'field-label';
label.setAttribute('for', input.id);

// Capitalize input name for label text
const labelText = input.name
? input.name.charAt(0).toUpperCase() + input.name.slice(1)
: 'Field';

label.textContent = labelText;

// Set placeholder
input.placeholder = labelText;

// Insert label before input
input.parentElement.insertBefore(label, input);
});
});
Loading