var $parent = $('.parent'),
$child = $('.child');
console.log($child);
$child.click(function(){
console.log('clicked');
$parent.replaceWith('<span class="child">abcd</span>');
});
.child{
cursor: pointer;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="parent">
<span class="child">abcd</span>
</div>
I'm new to job as a Junior Web Dev, I am studying jQuery and finding it interesting. I came across this little code. So when I click on the "Child", why isn't the console generating the message "Clicked" multiple times when I click it. It showed 1 time and stopped.