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

qt - QML MouseArea onWheel event not working properly when inside QML Scrollview -

java - is not an enclosing class / new Intent Cannot Resolve Constructor -

python - Error importing VideoFileClip from moviepy : AttributeError: 'PermissionError' object has no attribute 'message' -