What’s the difference between
$("<a>", {
"id" : "myId",
"text" : "my link",
"href" : "#",
"onclick" : function() { return false; }
);
and
$("<a>", {
"id" : "myId",
"text" : "my link",
"href" : "#",
"click" : function() { return false; }
);
?
Using
onclickcreates an attribute, and its value should be a string that refers to a function, not an actual function. Usingclickcreates a property on the element, and its value should be the function itself.So, the first one is written incorrectly; should be like this:
where “somefunction” is defined in the global scope: