Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Simulate click on select element with jQuery

Tags:

I use this code for simulate click on select element:

$(function(){    $("#click").click(function(){        $("#ts").click();        //$("#ts").trigger("click");    }); }); 

and HTML code is:

<select id="ts">     <option value="1">1</option>     <option value="2">Lorem ipsum dolor s.</option>     <option value="3">3</option> </select>  <input type="button" id="click" value="Click"/> 

I test click and trigger but both not work.

Thanks for any help.

like image 648
Morteza Avatar asked Nov 05 '12 15:11

Morteza


1 Answers

Well, you cannot attach click event to html select but you can do this tricky thing...

Take a look at here:

Live DEMO:

http://jsfiddle.net/oscarj24/GR9jU/

like image 177
Oscar Jara Avatar answered Oct 11 '22 03:10

Oscar Jara