I'm trying to accomplish read more feature in css3, ES6 and React.
I have a very long description (this comes from the server so it's dynamic) and I would like to add 'read more' feature in this. If a description is more than 3 lines then a button/link should could us as 'read more' and when I click that button then rest of the description should be displayed.
This is my code:
React:
<div className="content">
Description of the product
<button onClick=(() => {})>Read more</button>
</div>
CSS:
.content{
overflow: hidden;
line-height: 1.2em;
height: 3.6em;
}
What I am not able to figure out is when I click 'read more' button then how can change div id to make it's height to auto. I have the javascript code but I want to implement this in ES6
JS:
document.querySelector('button').addEventListener('click', function()
{
document.querySelector('#content').style.height= 'auto';
this.style.display= 'none';
});
Any help is highly appreciated!