jQuery > Events

Focus event in jQuery

How to attach focus event to an html element in jQuery?


To attach focus event to a html element, focus() method can be used.

<script>
    $("#txtFocus, #txtFocus1").focus(function () {
        alert("got focus");
    });
</script>

Above code will attach the focus event with the “txtFocus” and txtFocus1” textboxes and when these textboxes will get the focus (when it gets the cursor) then user will be alerted with "got focus" message. In this we have used multiple selector to selector multiple elements (txtFocus and txtFocus1).

 Views: 5141 | Post Order: 70



Write for us






Hosting Recommendations