javascript - Trying to make jquery work -
i having hard time getting jquery code work. i've tried examples , none work me. here example sort of works in chrome c drive, not dropbox on web, nor work @ in ie9.
when 'sort of' working on chrome c drive, starts out displaying tabs instead of tab supposed to. after clicking 1 of links shows corresponding tab.
my end goal modify website whole page doesn't flash while reloading every time click on menu item.
<!-- found at: http://jsfiddle.net/ufgts/ --> <script type='text/javascript' src="http://code.jquery.com/jquery-1.9.1.min.js"></script> <script type='text/javascript'> $(window).on('hashchange', function() { $('div.tab').hide(); $(location.hash).show(); }); $('a.hash').on('click', function(e){ e.preventdefault(); location.hash = $(this).data('hash'); }); </script> <a href="#a" data-hash="a" class="hash">a link</a> <a href="#b" data-hash="b" class="hash">b link</a> <a href="#c" data-hash="c" class="hash">c link</a> <div id="a" class="tab">tab a</div> <div id="b" class="tab hidden">tab b</div> <div id="c" class="tab hidden">tab c</div>
you forgot :
$(document).ready(function() { // code goes here });
so when attaching click handler a.hash
, there's no such element in dom.
Comments
Post a Comment