Button to open / close content

0

Hello, I'm new here and also with programming ... I have several divs with different contents and are hidden, I would like that when I click on a button continue reading it closes and displays the contents of a certain div and other divs is hidden and a button to close content as in the images .. I'm having a hard time making it work in all the blocks I needed to be more dynamic .. Thanks in advance

    
asked by anonymous 13.11.2017 / 04:38

2 answers

4

So I understand you want to create a "read more", I believe you will have to implement a bit of JS in your solution, a basic solution is as follows:

HTML

<p>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.</p>
<div id="more" style="display:none;">
    <p>Sed eleifend lectus id semper accumsan. Sed lobortis id ligula eget blandit. Integer interdum iaculis nunc, sed porttitor magna tincidunt in. Interdum et malesuada fames ac ante ipsum primis in faucibus. Aliquam lobortis accumsan tempor. Aliquam sollicitudin pulvinar est, quis convallis tellus.</p>
    <img..../>
</div>
<a href="javascript:showMore()" id="link">Read More >></a>'

The JS

function showMore(){
    //remove o link
    document.getElementById('link').parentElement.removeChild('link');
    //Mostra o conteúdo #more
    document.getElementById('more').style.display = "block";
}

There are also some JS libraries ready: link

    
13.11.2017 / 10:58
1

ex: link

Adds the divs that you want to show the same class ..

 <div class="to_show">

Then you can use jquery to add a listenner to the button and use the toggle function.

$(document).ready(function() {

    $("#buttonclick").click(function() {
            $(".to_show").toggle();
    });
});
    
13.11.2017 / 14:42