Reputation: 59
I am creating a dynamic anchor tag like this
var anch = $('<a />', {
'href': '#' + ctrlid,
'text': text
})
How do I add a click event while creating this tag that automatically calls a function say funcOne(ctrlid) and passes the ctrlid?
I tried this but no luck
var anch = $('<a />', {
'href': '#' + ctrlid,
'text': text,
'onclick': funcOne(ctrlid)
})
Upvotes: 1
Views: 97
Reputation: 342695
var anch = $('<a />', {
'href': '#' + text,
'text': text,
on: {
click: function () {
// do something
},
someOtherEvent: function () {
// do something
}
}
});
Upvotes: 3
Reputation: 87083
var anch = $('<a />', {
'href': '#' + ctrlid,
'text': text
}).click(function () {
// click handler code
});
Upvotes: 6