I'm dynamically creating a div. I'd like to add a onClick() event to it.
How do I add an onClick as in <div class="something" id="btnHome" onClick="return true"> to this?
abc.append(
$('<div />', { class: 'something', id: 'btnHome' })
);
EDIT:
I'm looking for an answer something like this
$('<div />', { class: 'something', id: 'btnHome' onClick: 'return true' })
....}).on("click",function() {return true;});or delegate like in the answer$('<div />', { class: 'something', id: 'btnHome' onClick: 'return true' })