Skip to content

Instantly share code, notes, and snippets.

@superscott
Last active December 19, 2015 10:09
Show Gist options
  • Save superscott/5937836 to your computer and use it in GitHub Desktop.
Save superscott/5937836 to your computer and use it in GitHub Desktop.
jQuery Search.
<div id='search_div'>
<input type="text" class="search-query" id="search_text">
<button class="btn" id='search_button'><i class='icon-search'></i></button>
</div>
<address id="2106">
<strong>RandoZZ ZZMcCracken</strong><br>
<small>home:</small> <a href="mailto:home@email.com">home@email.com</a><br><small>work:</small> <a href="mailto:work@email.com">work@email.com</a><br><small>primary:</small> <a href="mailto:primary@email.com">primary@email.com</a><br><small>other:</small> <a href="mailto:other@email.com">other@email.com</a><br>
<small>home phone:</small> 1-310-555-5555 <br><small>work phone:</small> 1-310-555-3333 <br><small>cell phone:</small> 1.310.555.1212
</address>
<script>
$(document).ready(function () {
$('#search_button').click(Search);
});
function Search() {
var mySearchArray = [];
search = $('input#search_text').val();
$('address').each(function() {
if( $(this).is(':contains('+ search +')') )
{
id = $(this).attr('id');
mySearchArray.push(id);
}
});
$(mySearchArray).each(function(index, value) {
$('address#'+ value +'').clone().appendTo('.results');
});
};
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment