Creating a “read more” link that extends the content on the page

后端 未结 10 2227
萌比男神i
萌比男神i 2021-01-03 06:06

I would like to create a read more link that would extend a paragraph already being shown to reveal the entire text on the same page. If this could be solves with HTML5 and

10条回答
  •  谎友^
    谎友^ (楼主)
    2021-01-03 06:37

    A vanilla JS alternative:

    The HTML:

    Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam porttitor feugiat ipsum quis ullamcorper. Nullam vitae velit vitae tortor semper tempor ac vitae magna. Maecenas a ullamcorper neque. Aliquam vitae tortor luctus nisi rutrum eleifend non non leo.

    Read More >>`

    The JS:

    function showMore(){
        //removes the link
        document.getElementById('link').parentElement.removeChild('link');
        //shows the #more
        document.getElementById('more').style.display = "block";
    }
    

提交回复
热议问题