Last active
August 18, 2023 06:18
-
-
Save joshhartman/76687f671cfa66e11d28a3e4b73e113f to your computer and use it in GitHub Desktop.
Ridiculously simple accordion without the jQuery UI library
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- Source: http://uniondesign.ca/simple-accordion-without-jquery-ui/ --> | |
<!-- JS --> | |
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.7.0/jquery.min.js"></script> | |
<script type="text/javascript"> | |
jQuery(document).ready(function($) { | |
$('#accordion').find('.accordion-toggle').click(function(){ | |
//Expand or collapse this panel | |
$(this).next().slideToggle('fast'); | |
//Hide the other panels | |
$(".accordion-content").not($(this).next()).slideUp('fast'); | |
}); | |
}); | |
</script> | |
<!-- CSS --> | |
<style> | |
.accordion-toggle {cursor: pointer;} | |
.accordion-content {display: none;} | |
.accordion-content.default {display: block;} | |
</style> | |
<!-- HTML --> | |
<div id="accordion"> | |
<h4 class="accordion-toggle">Accordion 1</h4> | |
<div class="accordion-content default"> | |
<p>Cras malesuada ultrices augue molestie risus.</p> | |
</div> | |
<h4 class="accordion-toggle">Accordion 2</h4> | |
<div class="accordion-content"> | |
<p>Lorem ipsum dolor sit amet mauris eu turpis.</p> | |
</div> | |
<h4 class="accordion-toggle">Accordion 3</h4> | |
<div class="accordion-content"> | |
<p>Vivamus facilisisnibh scelerisque laoreet.</p> | |
</div> | |
</div> |
not working
Still works, but I should have included a jQuery script tag and used the no conflict function. jQuery is required, but no jQuery UI components are. Updated. Also see the JSFiddle here: https://jsfiddle.net/5yg0rdkn/
I was not including jQuery
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
not working