My jQuery it's not working.
When the page loaded I want to show and hide some element.
It's work fine with change()
function but not working when use load()
and this is my code
$(document).ready(function () {
const text = '.text-type';
const sticker = '.sticker-type';
const image = '.image-type';
var collection = "form div[data-form-collection='item'] select";
$(collection).load(function(){
var type = $(this).val();
var row = $(this).closest("[data-form-collection='item']");
switch (type) {
case 'text':
row.find(text).show();
row.find(sticker).hide();
row.find(image).hide();
break;
case 'sticker':
row.find(text).hide();
row.find(sticker).show();
row.find(image).hide();
break;
case 'image':
row.find(text).hide();
row.find(sticker).hide();
row.find(image).show();
break;
}
})
})
What is wrong with my code ?
Thank you.