How to make it so that when you click on the "button" on the website, a DiV block appears with a ready text in some place under the button?
3 answers
At the block that you want to open, you put display: non. With js, you put a handler on a button that, when clicked, changes display: none to display: block. Something like this:
function viewDiv(){ document.getElementById("div1").style.display = "block"; }; #div1{ display: none; } <input type="button" value="Click" onmousedown="viewDiv()"> <div id="div1">ΠΠ»ΠΎΠΊ</div> - Thank! It seems everything is clear - Vaagn Akopyan
fixedwhy? o_O - Qwertiy β¦- @Qwertiy wrote randomly. I'll change it now. Thank. - nikit204
- And why
onmousedown? That is, 1. why such an obsolete form of adding a handler? and 2. why mousedown instead of click? - Qwertiy β¦ - If not difficult, can you implement the actual form of the handler? - Vaagn Akopyan
|
Here is also an interesting example (jquery)
$('.btn').click(function(){ $(".block_with_text").fadeToggle(100); }); <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js"></script> <button class="btn">ΠΠ»ΠΈΠΊΠ½ΠΈ ΠΏΠΎ ΠΌΠ½Π΅</button> <div class="block_with_text">Lorem ipsum dolor sit amet</div> |
Alternatively, you can do without js, it depends on the specific task and capabilities. For example, using a hidden checkbox and a label that will act as a pseudo-switch, switch the visibility of the DIV:
.text, input[type="checkbox"] { display: none; } input[type="checkbox"]:checked ~ .text { display: block; } /* Π‘ΡΠΈΠ»ΠΈΠ·Π°ΡΠΈΡ ΠΏΡΠ΅Π²Π΄ΠΎΠΊΠ½ΠΎΠΏΠΊΠΈ */ .btn { display: inline-block; margin-bottom: 4px; padding: 4px 8px; background-color: #ffffff; border: 1px solid #eeeeee; cursor: pointer; } <label for="pseudoBtn" class="btn">"ΠΠ½ΠΎΠΏΠΊΠ°"</label> <input type="checkbox" id="pseudoBtn"> <div class="text">ΠΠΎΡΠΎΠ²ΡΠΉ ΡΠ΅ΠΊΡΡ</div> |