I need to retrieve some datas from a value field containing a PHP variable. If I try to use JavaScript to output the value on the console I get an "Uncaught TypeError: document.querySelector(...) is null".
$locationMap = get_field('map_location');
<div class="coordinates">
<input type="hidden" id="lat" value="<?php echo $locationMap['lat']; ?>">
<input type="hidden" id="lng" value="<?php echo $locationMap['lng']; ?>">
</div>
<script>
let lat = document.querySelector('#lat').value;
let lng = document.querySelector('#lng').value;
console.log(lat);
<script>
If I replace the PHP variable inside the value field with something else (i.e. ABCDF) it work perfectly.