Legend hidden by default

0

I have a legend that when I load the page is opened by default and what I need is the opposite, that when loading the page is hidden and if I need to open it click.

My code is:

$(function() {
  // Set cursor to pointer and add click function
  $("legend").css("cursor", "pointer").click(function() {
    var legend = $(this);
    var value = $(this).children("span").html();
    if (value == "[-]")
      value = "[+]";
    else
      value = "[-]";
    $(this).siblings().slideToggle("slow", function() {
      legend.children("span").html(value);
    });
  });
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>

<legend class="section" style="color:#0CF">Contact Info <span>[-]</span></legend>
    
asked by Vieira 22.09.2017 в 17:29
source

1 answer

2

It should be enough for you to put the hidden style on the siblings that you want to appear hidden, like this:

<legend class="section" style="color:#0CF">Contact Info <span>[+]</span></legend>
<div style="display:none;">Información adicional</div>

With jQuery, you could also simulate the first click after registering the event, like this:

$("legend").css("cursor","pointer").click(function(){
    // ...
}).click();
    
answered by 22.09.2017 / 17:52
source