I want to be able to click on H2 and hide/show the elements under it.
There is no way for me to manually add a wrapping div to those paragraphs.
So far I have tried a variation of this code
var article = document.getElementsByTagName("article")[0].getElementsByTagName("*");
var myElement = document.createElement("div");
myElement.className="wrap";
for (var i = article.length - 1; i >= 0; i--) {
if (article[i].tagName =="P") {
myElement.appendChild(article[i])
};
};
document.body.appendChild(myElement);
I know that that’s no where near solving the problem, but that’s where I keep circling
You can do something like this to walk the DOM to find siblings. It’s going to be flakey without a wrapper though, you need a clear marker in the DOM to stop at.
If there’s an id or something on the next heading then you should be able to modify the code to check the nextSiblingsOfType function to look at the id rather than the nodeName.