I have a requirement and am not sure how to achieve it. I have a div with display:none
and I fetch the element to show in console with document.getElementByName
API. Is there a possibility that I can stop this from happening?
The expectation is if it has a display: none
, null should be the query result when I access it or its children
function fetchChildToNone(){
var _ele = document.getElementsByName('test_fetch');
console.log(_ele);
}
#div2{
display: none;
}
<!DOCTYPE html>
<html>
<head>
<title> Test fetching child to a parent with display:none</title>
</head>
<body onload="fetchChildToNone()">
<div id="div1">
<span> A div to not make the page empty</span>
</div>
<div id="div2">
<span id="test_fetch" name="test_fetch"> Hello World</span>
</div>
</body>
</html>