javascript - Hashchange to show divs -
i have number of divs on page, hidden default. jobs can selected links (to "#job8, example). i'm trying use hashchange in script check url specific hash , display appropriate div.
this example div
<div class="job-details" id="job8" data-jobid="8"> <p>job 8</p> </div>
this script.
$(document).ready(function(){ $('.job-details').hide(); }); $(window).bind('hashchange', function() { if (location.hash.substring(0,4) == "#job"){ var jobid = location.hash.substring(0); $('.job-details').hide(); $('[data-jobid="' + jobid + '"]').show(); } });
your line:
var jobid = location.hash.substring(0);
assigns '#' jobid
. presumably isn't want? want:
var jobid = location.hash.substring(4);
Comments
Post a Comment