<!DOCTYPE html>
<html lang="en">
<head>
<title>Focus & Blur</title>
</head>
<body>
<h2 id="title">Try</h2>
<form>
<input type="email" id="email-input" />
<button type="submit">submit</button>
</form>
</body>
</html>
input
const inputField = document.querySelector('#email-input');
const title = document.querySelector('#title');
inputField.addEventListener('blur', () => {
title.textContent = 'blur';
title.style.color = 'red';
} )
inputField.addEventListener('focus', () => {
title.textContent = 'focus';
title.style.color = 'blue';
})
This Pen doesn't use any external CSS resources.
This Pen doesn't use any external JavaScript resources.