Reputation: 4403
Still learning jquery here and I've tried to setup a set of divs that expand and then close, however nothing is happening on the close. Can someone explain what I'm doing wrong?
Thanks!
Upvotes: 1
Views: 1315
Reputation: 196236
You are dynamically adding the span.close
element.
So you need to use the .live
method to bind the events..
$("span.close").live('click', function() {
$(this).parent('.post-big').hide();
$(this).parent().prev().show();
});
Also note that i used prev
as there is no next element (and you seem to want to bring back the one you close earlier..)..
working demo at http://jsfiddle.net/gaby/N6Jkw/1/
Upvotes: 1
Reputation: 227310
When you bind to $("span.close")
, the <span>
is not in the DOM yet. Try using .live()
here.
$("span.close").live('click', function() {
$(this).parent('.post-big').hide();
$(this).parent().next().show();
});
Upvotes: 0
Reputation: 27697
Your .close
<div>
s are created dynamically, so you need to use .live
- this will assign the click
handler to every new <div>
that's added to the DOM. See:
$("span.close").live("click", function() {
$(this).parent('.post-big').hide();
$(this).parent().next().show();
});
Upvotes: 3