Running javascript in a link

Just using javascript when clicked
<a href="javascript:void(0);" onclick="document.getElementById('my_id').style.display='block';" >Click Me</a>

You can also use this, but the need for the “javascript:” marker is arguably annoying when adding multiple javascript commands:

<a href="javascript: document.getElementById('my_id').style.display='block';" >Click Me</a>
Using javascript in addition to a href
<a href="\sompage" onclick="document.getElementById('my_id').style.display='block';" >Click Me</a>

<a href="\sompage" onclick="MyFunction();" >Click Me</a>
Using multiple javascript commands

Just add them one after the other

<a href="javascript:void(0);" onclick="document.getElementById('my_id1').style.display='block'; document.getElementById('my_id2').style.display='none'; my_function(); ">Click Me</a>

Using href=”#” or href=”javascript:void(0)” to do nothing

href=”javascript:void(0)” is usually the better choice.

href=”#” causes page to scroll to the top of the document unless you use “return false” in whatever javascript function is called.