show more/Less text with just HTML and JavaScript

前端 未结 8 2123
心在旅途
心在旅途 2020-12-10 04:45

I am needing to create a show more/less text function, but with just JavaScript and HTML.. I can\'t use any additional libraries such as jQuery and it can\'t be done with CS

8条回答
  •  生来不讨喜
    2020-12-10 05:15

    I'm not an expert, but I did a lot of looking to implement this for myself. I found something different, but modified it to accomplish this. It's really quite simple:

    The function takes two arguments, a div containing only the words "show more" [or whatever] and a div containing the originally hidden text and the words "show less." The function displays the one div and hides the other.

    NOTE: If more than one show/hide on page, assign different ids to divs Colors can be changed

    Here is text that is originally displayed

    show more

    more text

    Here is the Script:

    
    

提交回复
热议问题