Call JavaScript function from <a href>

Is a dynamic computer programming language.[5] It is most commonly used as part of web browsers, whose implementations allow client-side scripts to interact with the user, control the browser, communicate asynchronously, and alter the document content that is displayed.[5] It is also used in server-side network programming with runtime environments such as Node.js, game development and the creation of desktop and mobile applications.
Post Reply
dzcadii
Posts: 94
Joined: Sun Mar 01, 2015 4:36 am

Call JavaScript function from <a href>

Post by dzcadii » Sun Mar 01, 2015 10:57 pm

Tired of using onclick, onmouseover, etc. to call a JavaScript function?

Code: Select all

<!-- *************
      file name: js.js
*****************-->

function from_ahr(){
var my_alert = alert("Hello, you clicked the link");
}

Code: Select all

<!--******************
     file name: index.html
*******************-->
<html>
<head>
<script language="javascript" src="s.js"></script>
</head>
<body>
<a href="javascript:from_ahr();">Click me</a>
</body>
</html>

If you want it all in one file

Code: Select all

<!--********************
     file name: index.html
*********************-->
<html>
<head>
<script language="javascript">
function from_ahr(){
var my_alert = alert("Hello, you clicked the link");
}
</script>
</head>
<body>
<a href="javascript:from_ahr();">Click me</a>
</body>
</html>

Post Reply