I am trying to add read more / read less function to multi paragraph.
I use the following HTML and jquery. However if I click different 'read more' link, it does not work properly. 'read more' stay 'read more', or read more and read less texts become confused.
Could anyone tell me how to fix this?
Thanks in advance.
<div id="section1">
<div class="toppara">
<img src="images/toh_texture1a.jpg" width="90" height="90" alt="pic" />
<p>Content 1. </p>
</div>
<div class="morepara">
<img src="images/plucchini_texture02.jpg" width="90" height="90" alt="pic" />
<p>
Content 1-a.
</p>
</div>
<p class="togglebutn">
<a href="#">LESE MER</a>
</p>
</div><!-- section 1 -->
<!-- section 2 -->
<div id="section2">
<div class="toppara">
<img src="images/dandelion.jpg" width="90" height="90" alt="pic" />
<p>Content 2. </p>
</div>
<div class="morepara">
<img src="images/toh_texture1a.jpg" width="90" height="90" />
<p>
Content 2-a.
</p>
</div>
<p class="togglebutn">
<a href="#">LESE MER</a>
</p>
</div><!-- section 2 -->
<!-- section 3 -->
<div id="section3">
<div class="toppara">
<img src="images/plucchini_texture02.jpg" width="90" height="90" />
<p>Content 3. </p>
</div>
<div class="morepara">
<img src="images/dandelion.jpg" width="90" height="90" />
<p>
Content 3-a.
</p>
</div>
<p class="togglebutn">
<a href="#">LESE MER</a>
</p>
</div><!-- section 3 -->
<!-- section 4 -->
<div id="section4">
<div class="toppara">
<img src="images/toh_texture1a.jpg" width="90" height="90" />
<p>Content 4. </p>
</div>
<div class="morepara">
<img src="images/plucchini_texture02.jpg" width="90" height="90" />
<p>
Content 4-a.
</p>
</div>
<p class="togglebutn">
<a href="#">LESE MER</a>
</p>
</div><!-- section 4 -->
<script language="javascript" type="text/javascript">
$(function() {
// set a variable Toggled to false
var Toggled=false;
// Toggle a paragraph
$('.togglebutn a').click(function(){
var $parentpara = $(this).parent().prev();
if(Toggled==false){$(this).html('<span class="readless">read less</span>'); Toggled=true;}
else{$(this).html('<span class="readmore">read more</span>');Toggled=false;}
$parentpara.toggle('slow');
return false;
});
});
</script>