jQuery: How to add ‘onchange’ attribute in a ‘select’ tag?

<select id="sel_id">

Works for me if I use the native setAttribute().

Also, remember that you need quotes around the selector.

$("#sel_id")[0].setAttribute("onchange", "foo()");

the final html will be

<select id="sel_id" onchange="foo();" >

Also remember to define foo in the global namespace, and not inside jQuery’s .ready() function.