In the simplified code below the href is linked to a custom javascript function (MyFunction). When clicking on the link ('link text') nothing happens (while I'd expect an alert message 'Hello world') and the console shows an error 'Uncaught SyntaxError: Unexpected token !' at the start of the document, which I (also) dont understand.
Just wondering what is wrong in the code below (?)
<script type="text/javascript">
function MyFunction(message){
alert(message);
}
$(document).ready(function(){
var message="Hello world";
$('#myDiv').html('<a id="myLink" href="#" onclick="MyFunction('+message+');">link text</a>'); //looked at the example solution at http://stackoverflow.com/questions/1070760/javascript-function-in-href-vs-onclick
}); //$(document).ready
</script>
</head>
<body>
<div id="myDiv"> </div>
</body>
</html>