Download:
- baresearch.js (4258 bytes)
- baresearch.min.js (798 bytes)
It essentialy works like grep, but for HTML DOM.
The source code is written with an intention for you to modify it. It contains comments with suggestions for extending it's functionality.
If you want something more elaborate built with the same principles, there will be an extended version of this with fuzzy search and some other features in the future.
Now straight to the point. This is how you use it:
<!-- Include the script anywhere. It'll wait for the page to load. -->
<script src="./path/to/baresearch.js"></script>
<!--
Below is the container of our filtered search.
It doesn't need any special classes.
-->
<div>
<!-- The search box must have class="baresearch-search" -->
<p></p>
<input type="text" class="baresearch-search">
<p>
In between the elements managed by the library
you may have as many elements of your own as you want.
</p>
<!--
Now, a wrapper with items. Items are all of it's
immediate children. In this case it's the divs.
The h3-s and p-s are part of them, but not items
of their own. A wrapper of items must have a
class="baresearch-items".
-->
<div class="baresearch-items">
<!-- 1st item -->
<div>
<h3>This header is inside an item,</h3>
<p>the form of which doesn't matter.</p>
<p>All the text will be searched.</p>
</div>
<!-- 2nd item -->
<div>
<p>Another item</p>
<p>Note that items don't need</p>
<p>any special classes</p>
</div>
<!-- have as many elements as you want -->
</div>
<div class="baresearch-empty">
<p>
This is the message displayed when there
are no items matching the search.
</p>
<p>
The script hides it on load, so you don't
have to pre-hide it in your stylesheets.
</p>
</div>
</div>
That's it. You don't need to use any fancy JavaScript API — there is none.
All you have to do is include the script and put the classes in.
Here's a working example:
You can have multiple searches on the same page. The only thing you have to do is to keep them in seperate containers.
This website doesn't track you and doesn't have any ads.
If you've got a spare buck, please consider supporting me on PayPal.