This article describes the JS implementation of the hidden sibling elements, only the content of the JS file display method. Share to everyone for your reference, specific as follows:
The demo.html file here will briefly display the elements of the same level as the JS file after it is opened, and display the contents of the Demo.js file at the same level. The specific code is as follows:
Demo.html:
Demo.js:
Document.writeln ("<div id=\" contsononly\ ">");
Document.writeln ("<p> Content contents Contents Content </p>");
Document.writeln ("</div>");
Window.onload=function () {
var Contsononly=document.getelementbyid ("Contsononly");
var Contparent=contsononly.parentnode;
var Contsonlist=contparent.children;
for (Var i=0;i<contsonlist.length;i++) {
if (contsonlist[i]!=contsononly) {
Contsonlist[i].style.display = ' None ';}}
The effect chart is as follows:
More readers interested in JavaScript-related content can view the site topics: "JavaScript traversal algorithm and tips summary", "JavaScript switching effects and techniques summary", "JavaScript Search Algorithm Skills summary", " JavaScript animation effects and tips Summary, "JavaScript Error and debugging skills Summary", "JavaScript data structure and algorithm skills summary" and "JavaScript Mathematical Computing Usage Summary"
I hope this article will help you with JavaScript programming.