Switch effect in jquery by default

My requirement: when I press the "li" button, his brothers "p" should move down, and by successive click - up. I achieved this through the following code. But by default, "p" closes. Only when I push the slide up / down does it work. I want p elements to be copied (hidden) by default. How to achieve this?

HTML:

<ul id = "duration"> <li id="time">Time</li> <p><input type="text" id="from" /></p> <p><input type="text" id="to" /></p> </ul> 

Jquery:

  $(function(){ $('ul #time').toggle(function(){ $("#duration p").show("slow"); }, function(){ $("#duration p").hide("slow"); }); }); 
+4
source share
3 answers

Just hide them at the top of the page:

 $(document).ready(function() { $("#duration p").hide(); }); 
+5
source

$("#duration p").css("display",'none');

try adding this as the first line in $(function(){)

This will make all p hidden by default

+1
source

use this

 $("#duration p").toggle(); $(document).on("click", '#time', function(){ $("#duration p").toggle("slow"); }); 
0
source

Source: https://habr.com/ru/post/1487828/


All Articles