No it is unfortunately not possible.
I suggest you read these links: MDN | Display or Article from nomensa , that evoke the notion of DOM accessibility and visibility.
In fact, if you put an element to "display: none
", it will not be visible and will exit the DOM accessibility tree.
However, there are some techniques that will allow you to make an DOM element completely invisible and no longer considered to exist on the DOM.
Then there are obviously techniques that you should surely know
The first if you want to completely mask your parent div without worrying about its dimensions
, I propose the code below. The clip property is depreciating but without it, it's still going to hide our item.
console.log(document.getElementById('child').scrollHeight);
.hidden {
border: 0;
clip: rect(0 0 0 0);
height: 1px;
margin: -1px;
overflow: hidden;
padding: 0;
position: absolute;
white-space: nowrap;
width: 1px;
z-index: -1;
}
<div class="hidden parent" href="#main">
I am ignored by the DOM
<div id="child">I am child</div>
</div>
<span style="color:red">I am the N°1</span>
Otherwise, if you want to keep the dimensions of your parent div
, you can float it out of the DOM stream.
console.log(document.getElementById('child').scrollHeight);
.hidden {
height: auto;
width: auto;
visibility: hidden;
position: absolute;
z-index: -1;
}
<div class="hidden parent" href="#main">
I am ignored by the DOM
<div id="child">I am child</div>
</div>
<span style="color:red">I am the N°1</span>
I hope this answer will be helpful.