Nitin Aggarwal Nitin Aggarwal - 2 years ago 82
Javascript Question

Prevent dropdown until all options are completely added jQuery

I am adding options to my dropdown dynamically on click event. My problem is the dropdown drops before even all options are finished adding and user can see the appending of options.

My Code is something like below.

$(document).on('click', '.someDropdown', function(e) {
$(this).append('<option class="someClass" value="foo">Foo</option>');

How can I make sure the dropdown drops after all the options are finished adding?

Answer Source
$(document).on('mousedown', '.someDropdown', function(e) {
   $(this).append('<option class="someClass" value="foo">Foo</option>');

The mousedown event occurs when the left mouse button is pressed down over the selected element.

The mousedown() method triggers the mousedown event, or attaches a function to run when a mousedown event occurs.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download