About this jQuery snippet
This jQuery snippet creates an interactive UI behavior that toggles the visibility of content sections when their corresponding headers are clicked.
Demo
HTML
<div class="demo-container">
<div class="demo-header">From which language does the word “ketchup” come?</div>
<div class="demo-content"><p>Ketchup comes from the Chinese word, 'kê-tsiap', the name of a sauce derived from fermented fish.</p>
</div>
</div>
CSS
.demo-container {
margin: 0 auto;
max-width: 500px;
min-height: 240px;
padding: 2em;
border: 1px solid rgba(255, 255, 255, 0.45);
background: linear-gradient(to top, #ffffff 0%, #dfe9f3 100%);
border-radius: 6px;
}
.demo-header {
position: relative;
padding: 10px 24px 10px 10px;
background-color: #ECECEC;
border-top-right-radius: 6px;
border-top-left-radius: 6px;
cursor: pointer;
}
.demo-header::after {
position: absolute;
content: "\f0ab";
font-family: FontAwesome;
font-size: 16px;
color: #454545;
right: 6px;
}
.demo-header-close::after {
position: absolute;
content: "\f0aa";
font-family: FontAwesome;
font-size: 16px;
color: #9F0000;
right: 6px;
}
.demo-content {
display: none;
border: 1px solid #ECECEC;
padding: 20px;
border-bottom-right-radius: 6px;
border-bottom-left-radius: 6px;
}
JS
$(document).ready(function() {
$(".demo-header").click(function() {
$(this).next(".demo-content").slideToggle("slow");
$(this).toggleClass("demo-header-close");
});
});
Alternate table row styles
Conditional formatting of table rows
Copy text to clipboard
Disable space input in text fields
Multi step form with progress indicator
Read more or less
Remove the leading and trailing space
Short functions
Toggle visibility with a slide effect
Toggle visibility without pushing content down
Validate checkboxes
Validate input fields
Validate radio buttons
Validate TinyMce editor