How to make click function work for dynamically created DIV(say on some ohter click function) with some class or ID?
Hi, I have created div and assign id or class to this div on some clicking event using jQuery. After creating I want to make click function work on this newly created div. But that is not working. Here is the sample code.
Thanks in advance.
<html>
<body>
<div id="some_ID"> Click me to create new divs! </div>
<script>
$("#some_ID").click(function() {
var new_div = $('<div class="new_class"> I am created dynamically on clicking </div>');
$("#some_ID").append(new_div);
});
$(".new_class").click(function() {
alert("hello i am newly created class using another class ");
}
</script>
</body>
</html>
But highlighted part of code is not working. May be when page loads it doesnt find new_class class which is created after clicking some_ID on same html page. Please correct me!