<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<script src="jquery-1.11.1.js"></script>
<script>
$(function () {
$("#demo").delegate('.t1', 'click', function () {
alert("t1");
});
$("#demo").delegate('#t2', 'click', function () {
alert("t2");
});
$("#demo").delegate('.t3', 'click', function () {
alert("t3");
});
$("#demo").delegate('#t4', 'click', function () {
alert("t4");
});
Test();
});
function Test() {
var strHtml = "<div class='t1'>t1</div>";
strHtml += "<div id='t2'>t2</div>";
strHtml += "<div class='t3'>t3</div>";
strHtml += "<div id='t4'>t4</div>";
$("#demo").html(strHtml);
}
</script>
</head>
<body>
<div id="demo">
</div>
<div id="demo1">
</div>
</body>
</html>