-5

Link "Goods" click event is not working after "Shops" clicked

<div class="i_find">
    <div class="replaced_link">Goods</div>
    <div class="link_container"><a href="#" class="a_shops">Shops</a></div>
</div>

Full code: http://jsfiddle.net/01j2s7xj/12/

1 Answers1

1

you need to use event delegation here:

$("body").on('click','.a_shops',function(){ 
    $('.i_find div:eq(0)').replaceWith('<div class="link_container"><a class="a_goods" href="#">Goods</a></div>');
    $('.i_find div:eq(1)').replaceWith('<div class="replaced_link">Shops</div>');

});

$("body").on('click','.a_goods',function(){
    $('.i_find div:eq(0)').replaceWith('<div class="replaced_link">Goods</div>');
    $('.i_find div:eq(1)').replaceWith('<div class="link_container"><a class="a_shops" href="#">Shops</a></div>');
}); 

Working Demo

Milind Anantwar
  • 77,788
  • 22
  • 86
  • 114