jQuery .delegate() event
.delegate() event
The .delegate()
method binds a handler
independent of whether the DOM element exists.
<html>
<head>
<script src="http://java2s.com/style/jquery-1.8.0.min.js"></script>
<script>
$(function(){ <!--from w w w. ja v a2 s .c om-->
$("body").delegate("p","click",function(){
document.writeln('ouch');
}).css("color", "green");
});
</script>
</head>
<body>
<p>Hit Me! ja va2s.com</p>
</body>
</html>