## 2012-06-30

### jQueery

This is slightly bizarre. I was jumping through hoops trying to get a script to reset a dropdown after a successful ajax request. Quite pointlessly, as it turns out.

The dropdown:

<select id="pos" name="pos">
<option value="n">noun (名詞)</option>
<option value="v">verb (動詞)</option>
</select>


So after the user submits some data, the form, including the dropdown, is reset.

After trying all kinds of complicated nonsense with eq() and stuff:

$("#pages option").eq(0).attr('selected', 'selected');  ... it turns out that this is the way to do it: $("#pos").val("n");


I originally began the post with the intention of saying "how counterintuitive!" at the end, but in the seven minutes it's taken me to write this, I've completely changed my mind. It's the most simple and elegant way to do it, and I salute you, jQuery.