Home > Web Front-end > CSS Tutorial > How to prevent a tag from jumping in css

How to prevent a tag from jumping in css

醉折花枝作酒筹
Release: 2023-01-06 11:14:22
Original
4049 people have browsed it

Method: 1. Use "#", the syntax is "a href="#""; 2. Use "javascript:", the syntax is "a href="javascript:void(0)""; 3. Use getElementById to get the a tag, and use "return false;" to cancel the jump.

How to prevent a tag from jumping in css

The operating environment of this tutorial: Windows 7 system, CSS3&&HTML5 version, Dell G3 computer.

<a href="www.baidu.com">百度</a>
Copy after login

1. Let’s do the simplest thing first. We can add the # sign directly to the html code, as follows:

<a href="#">百度</a>   <!--点击时它会跳转到页面的最顶端了-->
Copy after login

2. Secondly, we The default event that blocks it is also the following:

<a href="javascript:void(0)">百度</a>  <!--直接在里面添加一个阻止事件,当然直接是"javascript:"也是可以的,最好还是写全吧-->
Copy after login

3. There is also our js method to block it. We still give the a tag an id. We only need to do the following Operation:

<a id="Header1_HeaderTitle" href="www.baidu.com">百度</a>
Copy after login
let div1 = document.getElementById("Header1_HeaderTitle");
div1.onclick = function(){
      return false;
}
Copy after login

Recommended learning: css video tutorial

The above is the detailed content of How to prevent a tag from jumping in css. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template