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:

page1

page2

appreciate help!

your selector wrong. change

$('#' + id).addclass('expanded'); 

Comments

Popular posts from this blog

c++ - CPP, 'X' button listener -

shared memory - gstreamer shmsrc and shmsink with h264 data -

.net - Bulk insert via Dapper is slower than inserting rows one-by-one -