I’m trying to show/hide multiple divs with classnames based on proximity to the anchor which triggers the JQuery. I think something is wrong with how I’m referencing the div which I want to show.
I have a Fiddle here: http://jsfiddle.net/lizfulghum/qKMH8/4/ and I’m assuming the issue is with this line: JQuery(this).next(".full").show();
The complete code is as follows:
HTML
<div class="teaser">
Blah blah blah
<a href="#" class="toggle">Toggle</a>
</div>
<div class="full">
Full Text Goes Here
</div>
<div class="teaser">
Blah blah blah
<a href="#" class="toggle">Toggle</a>
</div>
<div class="full">
Full Text 2 Goes Here
</div>
Javascript
jQuery(document).ready(function() {
jQuery(".full").hide();
jQuery(".toggle").click(function() {
JQuery(".full").hide();
JQuery(this).next(".full").show();
});
});
Could anyone enlighten me on this point?
You’ve mistyped
jQuerytwice. Also you have to go one level up in the DOM tree before calling.next():Fiddle
I’ve aliased
jQueryto$inside the DOM ready scope — the first parameter of the DOM Ready handler receives the jQuery object itself.$is faster to type and less likely to mistype. You can safely use this syntax in WP and other.noConflict()scenarios as well.Of course, if you have no other libraries taking the global
$and you’re not using a framework that puts jQuery intonoConflictmode, you can use$instead ofjQueryout of the box.