mousedown in select Firefox

Asked

Viewed 34 times

1

At the time of click in a <div> the <select> should open.

That way I can open the <select>.

$('.teste').click(function(){
  var element = $('#select')[0];
  var ev = new MouseEvent('mousedown');
  element.dispatchEvent(ev);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<select id="select">
  <option>1</option>
  <option>2</option>
  <option>3</option>
</select>
<div class="teste">Aperte-me</div>

The code however does not work in Firefox.

The amazing thing is MDN document MouseEvent.

As I can do mousedown about a <select> in Firefox?

  • Programmatically open selects is a nightmare, use a custom select, know how to do?

  • No, I don’t know how to do it.

  • Take a look here: http://answall.com/a/46056/129

  • Yes, I had seen this question and was using one of the solutions presented to my <select>, but the text inside it was too big and encavalava in the icon of :before. I used the :before in a <span> and I was able to format the <select> for Firefox as well.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.