I'm trying to insert a toggle button into a wordpress page that will change the state of all divs of class "foo".
Is there either a pure javascript way to do this, or some way of guaranteeing the js will load after the jquery.js loads? I don't really want to deal with trying to figure out how wordpress loads javascript and enqueuing files in the proper order or whatever, this should be 3 lines of javascript that is only needed on this one page.
My HTML / javascript knowledge is minimal, so please include the full code needed.
More details: There is jquery in my theme, however if I try to use the $(".CLASSNAME").toggle() syntax, I get
"Uncaught TypeError: undefined is not a function"
Which I assume is something to do with my "page" javascript being loaded before jquery is loaded.
I tried various things, like
CSS
.excerpt{
style="display: none"
}
HTML
<input type="submit" value="Show/Hide Excerpts" onclick="toggleDiv();"></input>
<div class="excerpt">text i want to toggle</div>
Javascript, inside "script" HTML tag
$(document).ready(function toggleDiv() {
$(".excerpt").toggle();
} )
This results in the aforementioned "Uncaught TypeError: undefined is not a function"
This looks promising, but I'm not quite sure how to tweak it to toggle / be linked to a button: https://stackoverflow.com/a/5836870/851192
For the gory details, This is Wordpress 4.0.1, TwentyFourteen Theme, on a page created with the W4 Post List plugin.
I've been at this for three hours :/ Sigh.