Add an onClick event to append()
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I'm dynamically creating a div. I'd like to add a onClick() event to it. How do I add an onClick as in to this? abc.append( $(' ', { class: 'something', id: 'btnHome' }) ); EDIT: I'm looking for an answer something like this $(' ', { class: 'something', id: 'btnHome' onClick: 'return true' }) 回答1: Event delegation is the right way to do it and @Tushar has the answer for you. But, if you were after something like this: $(' ', { class: 'something', id: 'btnHome' onClick: 'return true' }) Then, you may do: $(' ', { 'text': 'new', 'class':