I want to pass parameter when I click in <a href>, first I have this and works fine:
<a href="#" rel="like{{num}}"> I like </a>|
$("a[rel^='like']").click(function(){
$.ajax({
...
});
but I don’t know how to pass parameter to that function, so I do this:
<a href="#" rel="like{{num}}"
onclick="cap(para1, para2)"> I like </a>
Finally, in my Javascript I have this simple function:
function cap(para1, para2){
alert('here');
}
but I obtain this error:
ReferenceError: cap is not defined
Any idea?
A solution is to use data attributes :
You may also write it like this if you prefer a more structured approach :
Note that if the document isn’t an HTML5 document you’ll have to use the more compatible data function of jQuery (but there hardly is any reason not to use HTML5 doctype today) :