javascript - Open specific accordion tab using external link and hash -
hi i'm new in js sorry ask here know basic one, i'm working accordion plugin collects article users want put in accordion , view in accordion question how open specific tab when have dynamic id per article inside item of accordion.. im trying hook item using link, http//:example.com#id open specific tab in accordion here s plugin code. hook inside code , trigger click event open specific in accordion plugin
!(function($){
$.fn.spaccordion = function(options){ var settings = $.extend({ hidefirst: 0 }, options); return this.each(function(){ var $items = $(this).find('>div'); var $handlers = $items.find('.toggler'); var $panels = $items.find('.sp-accordion-container'); if( settings.hidefirst === 1 ) { $panels.hide().first(); } else { $handlers.first().addclass('active'); $panels.hide().first().slidedown(); } $handlers.on('click', function(){ if( $(this).hasclass('active') ) { $(this).removeclass('active'); $panels.slideup(); } else { $handlers.removeclass('active'); $panels.slideup(); $(this).addclass('active').parent().find('.sp-accordion-container').slidedown(); } event.preventdefault(); }); }); };
})(jquery);
a little thing is, can use .children('div')
instead of .find('>div')
.
but if want hash set can use window.location.hash
. default used identify element ids. ideally element want show doing
if (window.location.hash) { var $selected = $('#'+window.location.hash); if ($selected.length) { // need show element } }
Comments
Post a Comment