alert(document.activeElement.id == "val"); $("#val").focus(); alert(document.activeElement.id == "val");