Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
<script class="jsbin" src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<meta charset=utf-8 />
<title>Collapse fieldset when legend element clicked</title>  
</head>
<body>
  <div id=myDiv>
  <fieldset><legend>Awesome</legend>
    <p>
      HELLO THERE
    </p>
    <p>
      Awesome
    </p>
    awesome
  </fieldset>
  </div>
</body>
</html>
 
$("fieldset legend").click(function() { 
  if ($(this).parent().children().length == 2)
    $('#myDiv').toggle();
  else
  {
    $(this).parent().wrapInner("<span>");
    $($(this).parent().parent().find("*")).prependTo($(this).parent().parent());
    $('#myDiv').toggle();
  }
});
Output

You can jump to the latest bin by adding /latest to your URL

Dismiss x
public
Bin info
anonymouspro
0viewers