Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
<script src="https://cdnjs.cloudflare.com/ajax/libs/rxjs/4.0.6/rx.all.js"></script>
  <meta charset="utf-8">
  <title>JS Bin</title>
</head>
<body>
  <button class="toggleButton">Toggle panel</button>
  <div class="panel">Hi, I'm a toggleable panel</div>
  
</body>
</html>
 
.panel {
  margin-top: 1em;
  color: #fff;
  font-family: sans-serif;
  display: block;
  padding: 1em;
  background: red;
}
 
const toggleButton = document.querySelector('.toggleButton');
const toggleablePanel = document.querySelector('.panel');
const buttonInitialState = false;
const togglePanel = () => {
  const panelIsInvisible = toggleablePanel.style.display === 'none';
  toggleablePanel.style.display = panelIsInvisible ? 'block' : 'none';
};
if(!buttonInitialState) {
  toggleablePanel.style.display = buttonInitialState ? 'block' : 'none';
}
toggleButton.addEventListener('click',togglePanel);
Output 300px

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

Dismiss x
public
Bin info
anonymouspro
0viewers