如何获取动态生成元素的数据属性

在从服务器投掷动态内容(通过AJAX)时,我有以下响应。

Some content ... 

我已经使用live绑定了click事件。 问题出在我的点击事件中,我无法获取数据属性,因此手动附加不适合我的情况。 有任何想法吗?

示例代码:

  $('a.delContent').live("click",function () { var cid= jQuery.data(this, "contentid"); alert(cid); //undefined return false; } ); 

在Click事件处理程序中尝试:

 $(this).data('contentId') 

适用于jsfiddle: http : //jsfiddle.net/Mk2zy/

试试这个….

 var attrValue = $(serverresponse).find('').attr('data-contentId'); alert(attrValue );