PR_4Christ
New Member
This is the function I use to scroll down from navigation to content on the page by using it id \[code\]<h1 id="#someid">\[/code\] and \[code\]href="http://stackoverflow.com/questions/15464499/#someid"\[/code\] prosperity in anchor tags. Function works fine however it do not work on first time click after loading the page. Any idea guys how to fix it and what causes it ? \[code\]//EXTERNAL JAVASCRIPTfunction link(){ $('a[href^="#"]').click(function() { var target = $(this.hash); if (target.length == 0) target = $('a[name="' + this.hash.substr(1) + '"]'); if (target.length == 0) target = $('html'); $('html, body').animate({ scrollTop: target.offset().top }, 100); target[0].style.backgroundColor = 'red'; setTimeout(function(){ target[0].style.backgroundColor = 'dodgerBlue'; }, 8000); return false; });}\[/code\]This is my HTML I simply overwrite the anchor onclick property by linking it to my function link(); Which you can see above this text. \[code\]//HTML <li class="sub-menu-element"><a href="http://stackoverflow.com/questions/15464499/#DERMATOLOG" onclick="javascript:link()">DERMATOLOG</a></li>\[/code\]Any ideas? Many thanks for your help guys in advance.