Last active
December 19, 2015 10:09
-
-
Save superscott/5937836 to your computer and use it in GitHub Desktop.
jQuery Search.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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