No need to wrap your images in spans. You can just put the class for each image directly on it, and toggle it that way. Additionally, you might want to watch out for the functionality of .next()
, as it might not work how you are expecting it to. It only grabs the immediate next sibling. This means that if there are any siblings between the element you call it on and the one you are looking for, you won't find it.
Check out the documentation for .next()
: http://api.jquery.com/next/
Instead try using .nextAll()
with a filter selector to find the element you want.
Documentation for .nextAll()
: http://api.jquery.com/nextAll/
That being said, here's a demo that does what you want (I think): http://jsfiddle.net/Ender/9eXnW/1/
Basically what you want to do is just make sure that you have the visibility of each of the images set properly to start with, then just select them both and call .toggle()
on them in your click event.
Check out the code:
$(function() {
$('.entry').hide();
$('.header-person').click(function(e) {
e.preventDefault();
$(this).nextAll('.entry:first').slideToggle("fast");
$(this).children('.close-icon, .open-icon').toggle();
});
});
Additionally, I've changed your return false;
to e.preventDefault()