In the code that you see under the text, there is a <div>
and in it I wrote "Hello World" . I coded based on jQuery that when I click <div>
that class name is test
it creates a new <div class="test">..
.
The problem is that when I click on the new element which is generated with class name test
with text "Book", it does not create new element, where as if I click on "Hello World", it generates new element again.
If anyone helps me to solve this problem, I will be thankful.
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$(".test").click(function(){
$(this).after('<div class="test">Book</div>');
});
});
</script>
</head>
<body>
<div class="test">
Hello World
</div>
</body>
</html>
$(document).ready(function(){
$(".test").click(function(){
$(this).after('<div class="test">Book</div>');
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="test">
Hello World
</div>