Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery: .select() and .focus() method difference

Tags:

jquery

In jQuery, what is basic difference between .select() & focus() and what are their appropriate using places?

like image 356
thecodeparadox Avatar asked Jun 07 '11 09:06

thecodeparadox


2 Answers

They have their differences:

  • .select(): will fire when TEXT is selected.
    • Limitted to <input> and <textarea> elements.
  • .focus(): will fire when an element receives focus i.e. an input box is clicked on, tabbed into, etc.
    • Also limitted but to a wider range of elements, mostly form elements such as <input>, <select>, <a>
like image 71
Gary Green Avatar answered Sep 19 '22 01:09

Gary Green


From the jQuery documentation:

select

The select event is sent to an element when the user makes a text selection inside it. This event is limited to <input type="text">fields and <textarea> boxes.

focus

The focus event is sent to an element when it gains focus. This event is implicitly applicable to a limited set of elements, such as form elements (<input>, <select>, etc.) and links (<a href>). In recent browser versions, the event can be extended to include all element types by explicitly setting the element's tabindex property.

like image 28
Aleksi Yrttiaho Avatar answered Sep 21 '22 01:09

Aleksi Yrttiaho