What I want to achieve, is - when user clicks the "read more" link:
- it's removed
- changes it's label to "read less"
- this new "read less" link is added to next element of it's parent (readmore_holder)
- "readmore_holder" is displayed;
Then there should be the other part with "read less" to swap links back again and to hide readmore_holder
, but since I cannot even get the alert()
to show up, I'm kinda lost.
What is the problem here?
P.S. If there are ways of simplifying this snippet, would really appreciate it.
Thanks in advance!
EDIT: Code from jsFiddle example.
$('.readmore_holder').hide();
$('.readmore_holder').prev().append(' <a href="javascript:void(0);" class="toggleon">read-more</a>');
$('.toggleon').click(function() {
$(this).parent().next().append(' <a href="javascript:void(0);" class="toggleoff">read-less</a>');
$(this).parent().next().fadeIn();
$(this).remove();
});
$('.toggleoff').click(function() {
alert('works!');
});
HTML
<p>Headline is right here</p>
<p class="readmore_holder">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas eget suscipit ante. Pellentesque egestas varius dolor, sit amet blandit erat luctus quis. Nunc semper odio a orci vulputate ut pulvinar mi consequat. Praesent molestie accumsan velit, nec vehicula velit mattis vitae. Proin libero mauris, ultrices eu congue quis, sollicitudin et eros. Phasellus tortor mauris, imperdiet in euismod ut, tempor id ante.</p>