So I can see the options of the select element but I need to click on it. What if I want to use a function? When something happens this select element should be selected, me
Just an update here as the accepted answer is correct but outdated and initMouseEvent is soon to be deprecated. [See: https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/initMouseEvent]
Use the following instead: new MouseEvent [See: https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/dispatchEvent]
Example code:
var el = $('select'); // grab the input (jQuery)
var event = new MouseEvent('mousedown'); // create the event listener
el.dispatchEvent(event); // attach the event listener to the element