Forum:Hiding text with javascript/jQuery

tl;dr: I'm writing Javascript code to hide spoilers in articles on Amalur Wiki and need help hiding text nodes (text not wrapped in any tags).

To spare y'all having to look for the link, yes, I know there's a similar script on dev wiki, but it hides the entire article, while I only want to hide sections that contain a spoiler tag. E.g consider a page like this:

Description
Some spoiler-free text here...

Spoiler-heavy text here

more spoilers...

Location
blah blah

Gallery
gallery code here What I want is to hide the content between and the next section header.

I already have the code for this (found here), but need help hiding text nodes that somehow sometimes appear in articles. Here's an example of how the script works - first case it works perfectly, second it does not hide all content. What breaks it is the fact that sometimes plain text is rendered as text nodes instead of being wrapped in p tags, despite no major differences in wiki markup. The example problematic page is here and the good page is here. Spoilers are hidden on page load, and can be shown by clicking on the spoiler banner above the section to be revealed.

Now, I obviously don't want to scour the entire wiki looking for such pages and correcting the markup (don't even know what causes text to be rendered differently, we don't use p or span tags explicitly on our wiki, just plain wiki code). I tried searching on Google for generic ways to select text nodes that appear after certain tags, but it seems that's not possible.

Main point: Is there a more wiki-specific way to select and hide such text nodes?

-- Gyumaou (Talk)  10:48, May 15, 2012 (UTC)