It's because the new .two
is added dynamically, but the click handler has already been attached to existing .two
divs, before the new one exists. You need to attach the handler to an element that will always exist, and then use that to handle clicks to child elements. This is called event delegation. In jQuery it would be done like this:
$('.galery').on('click', '.two', change_content);
So, .galery
responds to all click to it and its children, and if the click target matches the selector in the on()
call (.two
), it will call the handler function.