Expand search box on click jQuery script


In this lesson you are going to see how to expand search box (text box) on focus using jQuery.

We are going to use three jQuery functions to achieve this effect:

1. focus()
2. blur()
3. animate()

Basically all of us think, we have to write this expand animation in an onClick event, even my title is saying onClick, but that is not correct.  onClick event works only on mouse click instead if you use focus, it works for both mouse and keyboard (using tab key) etc.,

So let’s see the coding:

#searchbox is the id of the text box i used.

The basic idea is when the cursor comes (focus) into the text box increase the width of the text box to 150px with a slow animation effect and when the cursor goes (blur) out of the box decrease the size to 100px with the same animation effect.

Here is the entire code so you can play around with it,

And here is the demo,




Related Posts

Leave a Reply