Page 1 of 1
jQuery - Click element effects next element of type?
Posted: Fri Oct 26, 2007 2:28 pm
by JAB Creations
There was a thread that I've been searching for that someone shared how to collapse a div following a a header without using IDs or classes but programming jQuery to simply seek the first element after the trigger element of a type.
So for example I want to have all h2 elements collapse the first following div with the following HTML code...
Code: Select all
<h2>header</h2>
<div>some content here</div>
Posted: Fri Oct 26, 2007 3:14 pm
by nickvd
Untested (and I haven't touched JS in weeks)...
Code: Select all
$("h2").click(function () {
$(this).next('div').hide();
});
Posted: Fri Oct 26, 2007 3:27 pm
by JAB Creations
That helps me tremendously!
The only problem I'm having right now is that the script toggles the div to collapse and then automatically expands the div element? The desired behavior would have the div not expand until the second click.
Code: Select all
$("h2").click(function () {
$(this).next('div').BlindToggleVertically(1000,null, 'bounceout');
});
Posted: Fri Oct 26, 2007 3:56 pm
by JAB Creations
That problem has been solved, just had to remove old functions.
Is there a way to limit this trigger to only occur within a parent element (via ID such as #content)?
Posted: Fri Oct 26, 2007 4:30 pm
by nickvd
Just modify the 'CSS' selector used to trigger the event...
$('h2') -> $('#content h2')
Posted: Fri Oct 26, 2007 6:49 pm
by arpowers
have you tried .slideToggle() ?
Posted: Fri Oct 26, 2007 6:57 pm
by nickvd
arpowers wrote:have you tried .slideToggle() ?
He's currently using BlindToggle(), different effect, same process...
<edit>heh.. blingtoggle

</edit>
Posted: Fri Oct 26, 2007 7:01 pm
by JAB Creations
I tried slideToggle though it has a sort of pop effect at the beginning or ending of the animation. Not sure what (besides the pop) is supposed to be different between the two effects?
One more question, what rules can I use to restrict animation in specific instances? Thanks for your help!