Jump to content

JavaScript:void()


Don E

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...