Change only the image inside same div when option from dropdown is chosen

核能气质少年 提交于 2019-12-08 18:12:30

You are binding your javascript on document load. That's why this happening. You need to bind it on element created dynamically. Cocoon provide way to bind javascript on dynamic generated elements.

$('#container').on('cocoon:after-insert', function(e, insertedItem) {
  // ... do something
});

https://github.com/nathanvda/cocoon#callbacks-upon-insert-and-remove-of-items here list of all the call back events. Hope this help you!

So, cocoon dynamically adds elements to the page. Your jquery only binds to elements currently on the page.

You should use the jquery on method.

Without any view code from your part it is a bit hard, but let us say we take the form element as the parent element which will be present after loading. So something like this should do the trick:

jQuery(function($) {
  $("form").on('change', '.bracelet-color-select', function(){
    $('.product-still-form').attr('src',$('.bracelet-color-select>option:selected').attr('src'));
  });
});
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!