How to set the focus in an element using JavaScript?

Q

How to set the focus in an element using JavaScript?

✍: Guest

A

Use the "focus()" method of the element object:
<script>
function setFocus() {
if(focusElement != null) {
document.forms[0].elements["myelementname"].focus();
}
}
</script>

2010-10-19, 3640👍, 0💬