The first parameter is the type of the event (like "click" or "mousedown" Here the button is inside another element, a

element. EDIT: For your updated question, code2 will always execute before code1, because as I said above an async Ajax callback will happen later (even if the Ajax response is very fast, it won't call the callback until the current JS finishes). The change event is fired for ,