javascript - opening accordion with hash tag -



javascript - opening accordion with hash tag -

i trying open accordion based on url hash tag. i've found similar responses each utilize different accordion.

the html script follows:

<div class="contractable"> <div class="header"> <h1>branding</h1> <a class="contracttrigger" href="#branded"></a> </div> <div id="branded" class="content"> <div class="spacing"> <p>text</p> </div> </div> </div>

and js is:

$(function() { $('.contractable').each(function() { // natural height. var $contractable = $(this); var naturalheight = $contractable.height(); $contractable.data('naturalheight', naturalheight); // set default properties. $contractable.find('.content').addclass('closed').css( { 'height': 0, 'overflow': 'hidden' }); }); $('.contractable .contracttrigger').click(function(e) { e.preventdefault(); var $trigger = $(this); var $contractable = $trigger.parents('.contractable'); var $content = $contractable.find('.content'); if($content.hasclass('open')) { $content.animate( { 'height': 0 }, 300, function() { $content.removeclass('open'); $content.addclass('closed'); }); } else { $content.animate( { 'height': $contractable.data('naturalheight') }, 300, function() { $content.removeclass('closed'); $content.addclass('open'); }); } } }); }); function closewindow() { parent.parent.gb_hide(); }

i can hash tag easy plenty var hash_value = window.location.hash.replace('#', ''); i'm stuck on how can match hash div id (as there few different divs), open accordion. help appreciated.

after assigning event, simulate click:

$(window.location.hash).click()

javascript accordion

Comments

Popular posts from this blog

How do I check if an insert was successful with MySQLdb in Python? -

delphi - blogger via idHTTP : error 400 bad request -

postgresql - ERROR: operator is not unique: unknown + unknown -