Link to home
Start Free TrialLog in
Avatar of erikTsomik
erikTsomikFlag for United States of America

asked on

jquery issue

I ma trying to do a read more/read less functionality but does not seems to get it working right. It seems like I can not access the class directly because it surrounded by p tag

The content looks like this
<p>
hello here
<span class="feedback-morecontent"> hello here 2</span>
</p>
<span class="feedback-showmore">Show More</span>

And the JS is here
$(".feedback-morecontent").hide();
                  $('span.feedback-showmore').on('click', function (e) {
                   
                     $(this).text($(this).text() == 'Show More' ? 'Show Less' : 'Show More');
                     $(this).prev("p").prev(".feedback-morecontent").slideToggle("slow");
                        e.preventDefault();
                });
ASKER CERTIFIED SOLUTION
Avatar of Tom Beck
Tom Beck
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I think this arrangement looks better.

<p>hello here </p>
<p class="feedback-morecontent"> hello here 2</p>
<span class="feedback-showmore">Show More</span>

Then for jquery:

$(document).ready(function(){
      $(".feedback-morecontent").hide();
      $('span.feedback-showmore').on('click', function (e) {
      
            $(this).text($(this).text() == 'Show More' ? 'Show Less' : 'Show More');
                  $(this).prev("p").slideToggle("slow");
                e.preventDefault();
    });
});