I have attached a onClick event handle to a tag. On click, I wanted to pick-up an attribute -- let's say, fn; and I want to call the function mentioned as the attribute value.
The following code does not work
<html>
<head>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.4.4.min.js"></script>
<script language="JavaScript">
var Test = Test? Test : new Object();
$(document).ready(function(){
Test.main();
})
Test.sub = function(){
alert('called');
}
Test.main = function(){
$('.caller').click(function(e){
e.preventDefault();
var fn = $(this).attr('fn');
alert('calling: '+fn);
return fn();
});
}
</script>
</head>
<body>
<a class="caller" fn="Test.sub" href="#">test call</a>
</body>
</html>
My questions are
- Is it possible?
- What am I doing wrong?
- What could be right approach to solve this issue?
Thanks
Nishant