trigger click event on select

trigger click event on select

Hi everyone.

I have been trying to develop a simple method of styling the button on select dropdowns.  Basically just positioning a span of the button on a select box that is styled as required.

That is trivial...

What I have so far failed to achieve is to get the select box to show its options when clicking this span - just want to have the select box drop down the options as it normally would.

tried .trigger('click') and .trigger('mousedown') but to no avail...

Here is what I have:

  1. $(document).ready(function(){
  2. $('select').after('<span class="cta arrow-down"></span>');
  3. $('input[type="submit"]').after('<span class="cta arrow-right"></span>');
  4. $('span.cta').each(function(){
  5. var $this = $(this);
  6. var $prev = $this.prev();
  7. var $dim = $prev.position();
  8. $this.css({'top':$dim.top, 'right':0, 'height':$prev.outerHeight(), 'width':$prev.outerHeight()});
  9. $this.click(function(){
  10. $prev.trigger('click');
  11. });
  12. });
  13. };
Any input from you guys would be very much appreciated.  I'd very much like to avoid using the dropdownReplacment plugin if possible.

Many thanks.