Toggle excerpt and content using jQuery

♀尐吖头ヾ 提交于 2019-12-04 19:00:23

Yes you were close, but using $('.excerpt').hide(); will hide all elements in the page with class excerpt that's why you need to reference the clicked element and find the appropriate content inside the article to show/hide:

 $(function () {
     $('.content').hide();
     $('a.read').click(function () {
         $(this).parent('.excerpt').hide();
         $(this).closest('.tenant').find('.content').slideDown('fast');
         return false;
     });
     $('a.read-less').click(function () {
         $(this).parent('.content').slideUp('fast');
         $(this).closest('.tenant').find('.excerpt').show();
         return false;
     });
 });
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!