I need to hide a section from an html page:
<h1 data-ng-show="!menuPinned && !isSaaS" class="logo floatLeft" aria-hidden="false"><span>XXX </span><span style="font-weight: bold;">XXX </span><span>XXXXX</span></h1>
The following code works fine in Chrome dev. tools
var ibmlogo = document.querySelectorAll('h1.logo.floatLeft');
ibmlogo[1].remove();
But when I load the page with the script active, the section (h1) won't disappear.
I believe this is because when the script runs, the DOM has not been completed loaded yet, hence the script fails to find the selector.
I have tried many different things (e.g. window.onLoad) but still my script is not effective. Last attempt (failed) is the following:
var logo = document.querySelectorAll('h1.logo.floatLeft');
logo.onload = function() {removeLogo()};
function removeLogo(){
console.log("### logo array lenght: " + logo.length);
logo[1].remove();
};
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…