How to bind “non mouse action” event to a dymaically created object in JQuery?

106
August 23, 2021, at 5:00 PM

I am using multiselect plugin for my multiple select dropdowns. Here is the code:

$('#crew_id_1').multiselect({
    includeSelectAllOption: true,
    enableFiltering: true,
    maxHeight: 150
});

When html is loaded, #crew_id_1 is loaded dynamically. When I click an "Add More" button, more dropdowns are added like this #crew_id_2, #crew_id_3, ........... and so on.

I want each select element whose id starts with crew_id_ should have the multiselect initialized.

So I initialized the dropdowns like this:-

$('[id^="crew_id_"]').multiselect({
    includeSelectAllOption: true,
    enableFiltering: true,
    maxHeight: 150
});

Now I want even the dynamically created dropdowns to be initialized too. So I changed the code to:-

$(document).on('focus', '[id^="crew_id_"]', function(){
    $(this).multiselect({
        includeSelectAllOption: true,
        enableFiltering: true,
        maxHeight: 150
    });
});

However, the problem is that the dropdowns are only initialized when focus is set on them. I want any other event (any non mouse action event like 'load') so that it will be initialized without any click or focus.

This is because, the multiselect() gives a different look to the dropdowns. If I use 'focus', then until the focus is set on them, their appearance doesn't change.

READ ALSO
Can't ignore Content Description on new app

Can't ignore Content Description on new app

I have developed two other apps and was able to drop the Content Description when they runHowever, a new app I am working on will not drop it

96
Problem matching data in tables using regex

Problem matching data in tables using regex

Here, I want to update categoryName for image2 wherever characters in categoryID (image2) matches with categorID (image1)however, I want for categoryID "AA BB"(image2) should have category name updated as Archeology, Business

118
Using node-fetch module how can I use authenticated proxies?

Using node-fetch module how can I use authenticated proxies?

My goal is to send a request using node-fetch with authenticated proxies (Host, Port, Username and Password)I've been using https-proxy-agent but I get an error every time any other ways to use an authenticated proxy with node-fetch? Code:

42
Spring Security + JWT | False negative when comparing passwords

Spring Security + JWT | False negative when comparing passwords

This is my third update on this issue:

106