您好我正在尝试将jquery click事件处理程序写入由jquery动态生成的div元素。生成代码是
$(".catList").click(function(){
var category = document.getElementsByClassName(".catList");
var element = $("#" + $(this).attr('id')).html();
var toBeAdded = "";
var toAddTo = $("#wrapper");
toAddTo.html("");
$.post("getCategories.jsp", {categoryId: element}, function(data) {
var recordList = data.split("#");
for(i = 0; i < recordList.length; i++){
var data = recordList[i].split(":");
toBeAdded += "<br><br><br><div class=\"category\">";
toBeAdded += "<h1 class=\"userName\">";
toBeAdded += data[1];
toBeAdded += "</h1>";
toBeAdded += "<div class=\"content\">";
toBeAdded += data[3];
toBeAdded += "</div><br>";
toBeAdded += "<div class=\"like\" id='com-"+data[0]+"'>comments</div>";
toBeAdded += "<div class=\"like\" id='lik-"+data[0]+"'>likes "+data[2]+"</div></div>";
toAddTo.html(toAddTo.html() + toBeAdded);
toBeAdded = "";
}
});
});
这时我尝试这样做
$(".like").mouseover(function(){
alert("hi");
});
永远不会调用此事件处理程序。 DOM树有什么问题吗?