I have a website with a bunch of inputs that looks like this (I cannot edit the HTML since this part is automatically generated):
<div style="display: inline; position: relative;">
    <div>
        <label for="inputID">label here</label>
        <label >*</label>
    </div>
    <div>
        <div>
            <input type="text" fieldformat="None" id="inputID" placeholder="something">
        </div>
    </div>
</div>
I want to make it so that when the user is entering something on input field, the label will disappear appear
 ___________________________             _first name (label)_______
| first name (placeholder)  |  click    |                          |
|___________________________| --------> |__________________________|
here is my attempt at doing it with javascript:
function displayOnFocusAndOnFocusOut() {
    var inputs = [
        'inputID1',
        'inputID2',
        'inputID3',
        ...
    ]
    for(var i = 0; i < inputs.length; i++) {
        var input = document.getElementById(inputs[i])
        input.onfocus = function() {
            input.parentElement.parentElement.parentElement.firstChild.style.display = 'none'
            console.log(input.parentElement.parentElement.parentElement.firstChild)
        }
        input.onfocusout = function() {
            input.parentElement.parentElement.parentElement.firstChild.style.display = 'block'
        }
    }
}
However this doesnt work as the label still displays when I click on the input, and with a console log it shows that only the last input is affected. I've also tried adding !important but it still does not work.
How can I fix this?
Thanks
 
    