javascript - What is stopping my JS from getting my URL Hash? -
so trying add class on element, after hyperlinking separate page. have link on page1 set this:
<a href="https://jsfiddle.net/mv7nneu4/2#redbox">go redbox</a>
and on page2 running function:
$(function() { var id = window.location.hash; $(id).addclass('expanded'); }); this div should affecting:
<div id="redbox" class="red"> hajkldjfs </div> which, should grabbing hash, adding class expanded element. class never gets appended , console has no errors.
here 2 js fiddle links created simulate this:
appreciate help!
your selector wrong. change
$('#' + id).addclass('expanded');
Comments
Post a Comment