html5 - href link to load page and excute specfic jquery depending on link -


i need link go page , run specific jquery script depending on link. possible?

heres menu:

       <div class="navdropdown">                         <ul class="nav ">                 <li><a href="page/index.html#content1">content 1</a></li>                 <li><a href="page/index.html#content2">content 2</a></li>                 <li><a href="page/index.html#content3">content 3</a></li>                 <li><a href="page/index.html#content4">content 4</a></li>             </ul>         </div>     </li> 

on page/index.html have 4 div #content1 & on different content in. css of #content is:

display:none;

and jquery change correct div display correct selection.

display:block;

i cant head around this. please? :)

you might need use plugin jquery.ba-hashchange.js if want this:

html:

<div class="navdropdown">                 <ul class="nav">         <li><a href="#content1">content 1</a></li>         <li><a href="#content2">content 2</a></li>         <li><a href="#content3">content 3</a></li>         <li><a href="#content4">content 4</a></li>     </ul> </div>  <div id="content1" style="display: none;">div #content1</div> <div id="content2" style="display: none;">div #content2</div> <div id="content3" style="display: none;">div #content3</div> <div id="content4" style="display: none;">div #content4</div> 

jquery (onload):

$(window).hashchange(function(e){     var hash = window.location.hash;     var id = hash.substring(1, hash.length - 1);     id = "div[id^='"+id+"']";     $(id).hide();      $(hash).show();     });  $(window).hashchange(); 

demo


Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -