Jump to content

JavaScript:void()


Don E
 Share

Recommended Posts

Hello everyone, I know what javascript:void() does when that's set for the a's href, but can anyone explain how parameters are passed to void? For example, if you mouse over the 'code' button and look down at the status bar of your browser, you'll see: javascript:void('Code').I know what javascript:void(alert("Hello world")) does if it's set to the href, but when something like 'Code' is being passed, where exactly is it being passed to, a function? And if so, is that function returning false so that the a(link) doesn't load/take you to a new page? Thanks.

Link to comment
Share on other sites

According to the Mozilla Developer Network, void() evaluates an expression and returns undefined.

void(document.body.style.backgroundColor='green');

Using javascript:void(0) in URLs is, as far as I know, a bad practice, because the link is not performing its function as an anchor anymore. Javascript should be triggered by the click event of a link.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...