+ 2

Read more

Hello I want to make a "read more" so when you click read more, the text expands but when you open an other read more the first text is going to hide agian

21st Jun 2017, 12:11 PM
MC Creators Animation Studios BTS
MC Creators Animation Studios BTS - avatar
6 odpowiedzi
+ 5
I just made a simple code for you check it out . https://code.sololearn.com/WWYluMnkrHdv/?ref=app
21st Jun 2017, 5:49 PM
Harun Mohamed
Harun Mohamed - avatar
+ 1
Here is a basic concept of doing it. I'm not sure if you're limited to only JS and HTML, but you can do it much easier with jQuery, and can even easily animate it so it looks prettier. Throw a little CSS at it also, and it'll be less rigid. Hope this helps. HTML: <button onclick="readMore()">Read More</button> <div id="divReadMore"> This is stuff that I want you to read! So...read it! </div> <button onclick="readMore2()">Read Even More</button> <div id="divReadMore2"> This is stuff that I want you to read! </div> JS: function readMore() { var x = document.getElementById('divReadMore'); var y = document.getElementById('divReadMore2'); if (x.style.display === 'none') { x.style.display = 'block'; } else { x.style.display = 'none'; } if (y.style.display === 'block') { y.style.display = 'none'; } } function readMore2() { var x = document.getElementById('divReadMore2'); var y = document.getElementById('divReadMore'); if (x.style.display === 'none') { x.style.display = 'block'; } else { x.style.display = 'none'; } if (y.style.display === 'block') { y.style.display = 'none'; } }
21st Jun 2017, 1:42 PM
AgentSmith
+ 1
The code that I posted was just an example for you. You can change the button element to whatever element you want. Most elements have the 'onclick' property that you can execute JS functions from easily. SYNTAX: <element onclick="script"> SUPPORTED HTML TAGS: All HTML elements, EXCEPT: <base>, <bdo>, <br>, <head>, <html>, <iframe>, <meta>, <param>, <script>, <style>, and <title>
21st Jun 2017, 6:49 PM
AgentSmith
0
Help
21st Jun 2017, 12:27 PM
MC Creators Animation Studios BTS
MC Creators Animation Studios BTS - avatar
0
I do not want a button I want a text to click
21st Jun 2017, 1:54 PM
MC Creators Animation Studios BTS
MC Creators Animation Studios BTS - avatar
0
It works, thanks all
21st Jun 2017, 6:49 PM
MC Creators Animation Studios BTS
MC Creators Animation Studios BTS - avatar