My Html looks like
<h3><a href="#" title="story title">Story Title</a>
<img class="expandstory" src="/images/plus.png" /></h3>
<div class="description">Short description about the story</div>
<h3><a href="#" title="story title">Story Title</a>
<img class="expandstory" src="/images/plus.png" /></h3>
<div class="description">Short description about the story</div>
My jquery looks like
$('.description').hide();
$('.description:first').show();
$('.expandstory:first').attr('src','/images/minus.png');
$('.expandstory:first').addClass('collapsestory');
$(".expandstory").click(function() {
if($(this).attr('class')=='expandstory') {
$(".description").slideUp(500);
$(this).parent().nextAll('.description:first').slideToggle(500);
$(this).attr('src','/images/minus.png');
$(this).addClass('collapsestory');
$(this).removeClass('expandstory');
}
else {
$(".description").slideUp(500);
$(this).attr('src','/images/plus.png');
$(this).addClass('expandstory');
$(this).removeClass('collapsestory');
}
});
I am making a simple thing more complex and more over this is not working when I expand/collapse the div multiple times.
I cannot change the HTML file. Please provide me good solution in jquery. Thanks in advance.