How can I make an appended element clickable? In this case, clicking "Hello" should change the background of #div1.
<!DOCTYPE html>
<html>
<head>
<script src="http://code.jquery.com/jquery-latest.min.js"></script>
<script>
$(document).ready(function(){
$("button").click(function(){
$("#div1").append("<p>Hello</p>");
});
$("p").click(function(){
$("#div1").css({"background":"#0ff"});
});
});
</script>
<style>
#div1 {
background:#ff0;
height:100px;
margin:0 0 50px 0;
}
p {cursor:pointer;}
</style>
</head>
<body>
<div id="div1"></div>
<button type="button">Click Me!</button>
</body>
Thank you!