My JavaScript code in Php/WebStorm is displaying a warning that the property id
is not defined in the element/node, even though the element is a firstChild
fetched from its parent element.
function hideChildAndUpdateID(title) {
let parent = document.getElementById('parent');
let child = parent.firstChild;
// Hiding the child.
child.style.display = 'none';
// Temporary ID so we can find it later.
child.id = 'child-tmp-id'; // Warning occurs here
}
The message from Php/WebStorm reads:
Property id is not defined in type Node less... (Ctrl+F1)
Inspection info: This inspection reports assignments to undefined properties of explicitly type-annotated variables.
Despite the warning, the code works as intended. The child
element's id
does get changed, but the warning persists and bothers me.
I attempted using
child.setAttribute('id', 'child-tmp-id')
, but it did not work correctly.
Is there a specific convention for dealing with firstChild
, or is this issue unique to Php/WebStorm?