1
In the yellow div (id="conteudo"
) there’s the pink div (id="conteudo-interno"
) and an image.
The button makes the yellow div is clean, but I would like everything to disappear, except the pink div (conteudo-interno
)
Is there any way I can keep that div somewhere and then just call her up and have her show up again?
function limpaConteudo() {
$('.conteudo').empty();
}
#conteudo{
width:300px;
height:300px;
float:left;
background-color:#ff1;
display: initial;
margin: auto;
z-index: 6;
overflow: hidden;
}
#conteudo-interno{
width:100px;
height:100px;
background-color:#f1f;
float:left;
display: initial;
margin: 50 50;
}
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"> </script> <!-- Biblioetca JQuery -->
</head>
<body>
<button onclick="limpaConteudo()"> Press Here </button>
<div id="conteudo" class="conteudo">
<img src="http://a.deviantart.net/avatars/i/n/indistinguishable.png?2">
<div id="conteudo-interno"> Hello World! </div>
</div>
</body>
</html>
Could use a $('#content img'). Hide() to disappear and a $('#content img'). show() to come back. If the goal is only to hide.
– Rafael Weber
So, in this example it would only be an image, but in a real case it could be several images understand? Then I believe that the correct one would be to delete
– Sora
@Your pink div content is dynamic ? If it’s a solution with predefined content, it won’t suit you
– Caique Romero
So, to solve the @Caique problem I used the principles of the @Felipe response, where I used the
.html
: Function cleanConteud() { $('.contents'). Empty(); $('.contents'). html('<div id="inner-contents"> Hello World! </div>'); }– Sora
Understood, see my reply I tried to demonstrate that it is possible to store the content even if it varies, in the comment above if you make a change in the debt (inner-content) automatically you would have to edit the line $('.content'). html('<div id="internal-content"> Hello World! </div>'); causing unnecessary repetition.
– Caique Romero