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.

    $("#txtFocus, #txtFocus1").focus(function () {
        alert("got focus");

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: 901 | Post Order: 70

Write for us