jquery expanding search bar

How we can create an expanding search bar using JavaScript? Solution: See this jQuery Expanding Search Bar With CSS, Search Input Expand.

Previously I have shared some search input programs, but this is an expanding bar. Basically expanding bar is a search icon box and it expands to input field on mouse click or tap. These kinds of search bar you can see most of the website’s navbar, they use this to save space and create an attractive UI.

Today you will learn to create a search input expand program. Basically there is a box with a search icon and when you will click or tap on that it will expands to search input and after typing some query the icon will change to GO button. And after clicking on search or go action it will become the same search icon box which it previously was.

So, Today I am sharing jQuery Expanding Search Bar With CSS. There I have used jQuery for easy work and save time, If you want to create it with pure JS then it will little complicated and take much time. jQuery is JS library and libraries are created for easy work, that’s why I am putting this post in JavaScript category.

If you are thinking now how this expandable search input actually is, then see the preview given below.

Preview Of Search Input Expand

See this video preview to getting an idea of how this expandable input looks like.

Live Demo

Now you can see this visually, you also can see it live by pressing the button given above. If you like this, then get the source code of its.

You May Also Like:

jQuery Expanding Search Bar With CSS Source Code

Before sharing source code, let’s talk about it. First I have created an HTML form inside a div and put a text input, a submit input and a span placed inside the form. I have placed the text input for the search bar and the submit input for search button and span for placing the search icon. For placing icons I have used the font-awesome library (get).

Now using CSS I have placed all the elements on the right place, as you can see in the preview. I have placed the search icon span over the submit button and hides the text input by putting 0% width. There are a lot of basic CSS commands I have used like height, width, margin, padding, etc.

jQuery Handling here the toggle feature and changing CSS values dynamically by changing the class or ID names. Also, jQuery changing here display properties by modifying the CSS values. Left all other things you will understand after getting the codes, I can’t explain all in writing. For creating this program you have to create 3 files. First for HTML, second for CSS, and the third for JavaScript. Follow the steps to creating this without any error.

index.html

Create an HTML file named ‘index.html‘ and put these codes given below.

style.css

Now create a CSS file named ‘style.css‘ and put these codes given here.

function.js

The final step, create a JavaScript file named ‘function.js‘ and put the codes.

That’s It. Now you have successfully created jQuery Expanding Search Bar With CSS, Search Input Expand program. If you have any doubt or question comment down below.

Thanks For Visiting, Keep Visiting.

LEAVE A REPLY

Please enter your comment!
Please enter your name here