Using a function in an anchor

Last updated:

Sometimes you may need a function be invoked when a sentence, or an image, within an anchor tag

<A HREF="...">sample sentence</A>
is clicked.
You do this by specifying
<A HREF="javascript:function(...)">sample sentence</A>
where function(...) is the function to be invoked when the sentence is clicked.

In the following example, when you click the sentence, a function is executed that opens the linked page in a pop-up window:

click me now
Note. The function mentioned must not return anything.

To know more about this subject, click here