Jquery is everywhere, its good. People like it. Its easy(ish) for beginners to create great web apps.

It’s also large, and a burden if you don’t really need it. There are plenty of things you can do in jquery that you can do without it. And sometimes in an easier fashion.

One thing I notice, is that many many people use the jquery autocomplete in order to give themselves a nice suggestive input dropdown. They are great, especially when using large unwieldy lists. But, what if I told you you could have all that, without including ANY js library?

HTML5 offers something called a datalist. This can be coupled up to a standard text input to provide a auto suggesting list. Clever huh?

See the following code: (excuse the short list of countries, I couldn’t be arsed to fill them all out for this example)

<input type='text' name='country' list='countryList' />

<datalist id='countryList'>
<option value='America'/>
<option value='Australia'/>
<option value='Austria'/>
<option value='Canada'/>
<option value='England'/>
<option value='Germany'/>
<option value='Poland'/>
<option value='Sweden'/>
</datalist>

The above input will take the list from the list property and fill the suggestions from the options within

Example here https://jsfiddle.net/christatedavies/5g0ecpkd/1/

Easy stuff. There’s a decent git repo that has lots of examples of things you don’t need jquery for, with examples:

https://youmightnotneedjquery.com/

By admin

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.