简体   繁体   中英

Preventing 'Jump to top" links

I have used this in my footer.php to prevent tooltip links I have from jumping to the top of the page,however by using this it also deactivates / breaks my navigation bar?

Is there a way to use this to prevent the 'jump to top' on tooltip buttons, but still keep the navigation bar from being effected?

<script>
jQuery( "a" ).click(function( event ) {
  event.preventDefault();
  $( "<div>" )
    .append( "default " + event.type + " prevented" )
    .appendTo( "#log" );
});
</script>

Link

You will see icons on the page representing "wifi" "bathrooms" etc. The below was used so that those tooltip links (#) do not make the page jump when clicked

This seemed to do the trick

<script>
 jQuery( 'a[href="#"]' ).click(function( event ) {
  event.preventDefault();
  $( "<div>" )
  .append( "default " + event.type + " prevented" )
  .appendTo( "#log" );


});
</script>

add return false as the last line of your function

<script>
 jQuery( "a" ).click(function( event ) {
  event.preventDefault();
  $( "<div>" )
  .append( "default " + event.type + " prevented" )
  .appendTo( "#log" );

  return false;

});
</script>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM