I am fairly new to jQuery and I am attempting to write a simple script that will show more text when a "show more" link is clicked.
Currently I am able to change the link text between "show more" and "show less", but I am still unable to toggle the two css classes. The first class hides the select content and the second class should display it.
Here is the code so far:
css
.hideThis{
display:none;
}
.showThis{
display:inline;
}
html
<div class="review">
<p >Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus pellentesque
sagittis velit, varius commodo odio accumsan ut. Etiam vestibulum commodo viverra.
Integer condimentum quis ligula eget interdum. Vivamus semper posuere sapien ut tristique
<span class="hideThis">Etiam vestibulum commodo viverra.
Integer condimentum quis ligula eget interdum. Vivamus semper posuere sapien</span>
<a href="#" class="showMoreText">... show more</a>
</p>
</div>
Jquery
$('.showMoreText').click(function(){
var text = $(this).html();
if(text == '... show more'){
$('.hideThis').toggleClass('.showThis');
$(this).html('... show less');
}else {
$('.showThis').toggleClass('.hideThis');
$(this).html('... show more');
}
});
edit:
added a JSFiddle How can I apply this to a page with multiple "showMoreContent" links?
Thanks
Chris