getComputedStyle wrong for placeholder on mobile
by kerfuffley
HTML
<script src="https://code.jquery.com/jquery-3.4.1.slim.js"></script>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.js"></script>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.css">
<div class="container">
<label class="control-label" for="whatever">Check it out</label>
<input class="form-control" id="whatever" type="text" placeholder="Here is my placeholder.">
<hr>
<pre class="debug-info-js"></pre>
</div>
CSS
.form-control::placeholder {
font-size: 11px;
}
JavaScript
function updatePlaceholderLength(el) {
var styles = window.getComputedStyle(el);
var placeholderFontSize = window.getComputedStyle(el, '::placeholder').fontSize;
document.querySelector('.debug-info-js').textContent = 'placeholder font size: ' + placeholderFontSize;
}
updatePlaceholderLength(document.getElementById('whatever'));