Here I am trying to add a few classes in this ".ingradient" class element when ".tt-select" select changes. So, I was almost there. But when I select the option, there is a list of ".ingradient" items. I need to perform the below code for that specific one who we selected currently. I know we can use $this keyword, But I can't write the code for it. Please help. Thanks
$('.tt-select').change(function(){
$('.ingradient').addClass('animate__animated animate__heartBeat');
const remClass = setTimeout(fnRemClass, 2000);
function fnRemClass() {
$('.ingradient').removeClass('animate__animated animate__heartBeat');
}
});
What I've tried yet but no success.
$('.tt-select').change(function(){
$('.ingradient', this).addClass('animate__animated animate__heartBeat');
const remClass = setTimeout(fnRemClass, 2000);
function fnRemClass() {
$('.ingradient', this ).removeClass('animate__animated animate__heartBeat');
}
});
Here is the ".tt-select" select fields.
And here is the ".ingradient" class where I need to add classes individually.
Hope, someone can help me to find out how I can use $this keyword properly here. Thanks
[EDIT] After receiving a suggestion on comments I tried this still with no success:
$('.tt-select').change(function(){
$(this).find(':selected')
.addClass('animate__animated animate__heartBeat');
const remClass = setTimeout(fnRemClass, 2000);
function fnRemClass() {
$(this).find(':selected')
.removeClass('animate__animated animate__heartBeat');
}
});