Answer the question
In order to leave comments, you need to log in
How to hide DIV without id or class in JS?
Hi
Can you please tell me how to hide a div that only has style.
This block hangs at the beginning of the body which has an id. The block itself contains a ton of styles. It would be possible to hide it as the first child block, but this block is not always there. This is a banner from the CMS so climbs. There is no access to the code, but there is access to html through a macro, that is, I can edit styles for c id or class blocks. You need to find it by style="..." and hide (in extreme cases, change the text)
Perhaps you can search by the text in the block or by styles, but I don’t know how. Found this code..
<div style="margin:5px;padding:5px">Text</div>
var els = document.getElementsByTagName('div');
for (var i = 0; l = els.length; i < l; i++) {
if (els[i].innerHTML == 'style....') {
els[i].parentNode.removeChild(els[i]);
}
}
Answer the question
In order to leave comments, you need to log in
If it is as stupid as possible, then here is https://stackblitz.com/edit/js-mfhn7x?file=index.js
[...document.querySelectorAll('div')].find(e => e.textContent === 'Text').style.display = 'none';
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question