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

Popular posts from this blog

html - Sizing a high-res image (~8MB) to display entirely in a small div (circular, diameter 100px) -

java - IntelliJ - No such instance method -

identifier - Is it possible for an html5 document to have two ids? -