Javascript:void (0) meaning

Source: Internet
Author: User

We often use code such as Javascript:void (0), so what does javascript:void (0) mean in JavaScript?

The key in Javascript:void (0) is the Void keyword, which is a very important keyword in JavaScript, which specifies that an expression is evaluated but does not return a value.

The syntax format is as follows:

<Head><Scripttype= "Text/javascript"><!--voidfunc () javascript:voidfunc () orvoid(func ()) javascript:void(func ())// -</Script></Head>

The following code creates a hyperlink, and nothing happens when the user clicks it.

<href= "javascript:void (0)"> Click here Nothing will happen </A  >

void (0) evaluates to 0 when the user links, but does not have any effect on Javascript.

In the following example, a warning message is displayed after the user clicks the link:

<Head><Scripttype= "Text/javascript"><!--// -</Script></Head><Body><ahref= "javascript:void (alert (' Warning!!! ')")>Dot me!</a></Body> 

The difference between href= "#" and href= "javascript:void (0)"

# contains a location information, the default anchor is #top that is the top of the page.

and javascript:void (0), only represents a dead link.

When the page is long, it uses # to locate the page in the format:# + ID.

If you want to define a dead link please use Javascript:void (0).

<ahref= "javascript:void (0);">Dot I'm not responding!</a><ahref= "#pos">Point me to the specified location!</a><BR>...<BR><PID= "POS">Trailing Anchor Point</P> 

Javascript:void (0) meaning

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.