I'm trying to make a simple jQuery accordion plugin and can't figure out why doesn't the 'this' keyword work as it should. Here's the code of the plugin:
(function( $ ){
$.fn.accrdn = function(userSettings) {
var defaults = {
toggle: true
};
var options = $.extend({}, defaults, userSettings);
var handle = this.find('.handle');//doesn't work!
if (options.toggle) {
handle.click(function(){
$(this).next('.panel').slideToggle();
});
} else {
handle.click(function(){
$(this).next('.panel').slideUp();
});
};
};
})( jQuery );
Now that the OP has provided an example fiddle of the code usage, the problem is the selector for the accordion div, it should be:
$(document).ready(function() {
$('.accordion').accrdn({toggle:true, slideSpeed:500});
});
NOTE: The selector was missing the . to identify it is a class selector
Here is the fix
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With