I modified the default placeholder color of my input to blue. How come I am seeing a black placeholder color when using JavaScript?
const fetchPlaceholderColor = () => {
let inputElement = document.querySelector('.myClass');
let inputElementStyle = window.getComputedStyle(inputElement, '::placeholder');
let resultContainer = document.getElementById('colorOutput');
let placeholderColor = inputElementStyle.getPropertyValue('color');
resultContainer.innerHTML = `Placeholder color: ${placeholderColor}`;
}
.myClass::placeholder {
color: #004085;
}
.marginTop20 {
margin-top: 20px;
}
<input
type="text"
placeholder="Enter name"
class="myClass"
/>
<button onClick="fetchPlaceholderColor()">Fetch placeholder color</button>
<div class="marginTop20" id="colorOutput"></div>