I have this function which is as follows:
function detectfieldchange(parent = '#slidesContainer', field = '.slide-type-selector') {
$(parent).on('change', field, function(event) {
$this = $(this);
console.log($this);
fieldtype = '.' + $this.val() + '-options';
allfieldtypes = $this.closest('.sliderow').find('.slide-type-properties');
allfieldtypes.fadeOut(300);
$this.closest('.sliderow').find(fieldtype).fadeIn(300);
});
}
and the issue is I want to run the function like this( As follows ) so that I can pass in any selectors I want but this does not work:
detectfieldchange(var1, var2);
Both var1 and var2 are defined variables with CSS selectors in term of strings like this var var1 = '.parent'; etc
While If I simply do a simple call to activate the default values of function params the function works perfectly like this:
detectfieldchange();
So, Having explained this, What could be a possible solution to achieve this. And one thing more to note here is that 'fields' are going to be dynamically added to the page that's why event delegation is necessary.