I have 300 plus list of items that I'd like to make easier for users to find what they are looking for. I want the element that contains what matches what the user types to move to the top of of the list or into another element at the top. my code looks like below. Any Ideas on how I can achieve that?
var $showYourself = $('.sort-plate').text;
var $rollCall = $('input#sort-plate').text;
$('#clicker').click(function () {
if ($showYourself === $rollCall) {
$('.sort-plate').appendTo('#show-here');
}
});
$(function () {
$('.name').html(function (i, html) {
return $.trim(html).replace(/(\w+)$/, '<span class="sort-by">$1</span>');
});
var $sortPlate = $("#plate");
$sortPlate.find(".sort-plate").detach().sort(function (a, b) {
return $(a).find('.sort-by').text().localeCompare($(b).find('.sort-by').text());
}).appendTo($sortPlate);
});
.name, .center, .phone {
width: 190px;
font-size: 16px;
color: green;
margin-bottom: 15px;
display: inline-block;
}
.sort-by {
color: red;
}
strong {
display: none;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="plate">
<from action="#">
<input type="text" id="sort-plate" />
<input type="button" id="clicker" value="submit" />
<div id="show-here">Resul</div>
</form>
<br />
<br />
<div class="sort-plate">
<div class="name"> <strong>Name</strong> Chibueze Okechukwu</div>
<div class="center"> <strong>Department</strong> Act Center</div>
<div class="phone"> <strong>Ext</strong> 5204</div>
</div>
<div class="sort-plate">
<div class="name"> <strong>Name</strong> Angelina Jolie</div>
<div class="center"> <strong>Department</strong> Act Center</div>
<div class="phone"> <strong>Ext</strong> 5204</div>
</div>
<div class="sort-plate">
<div class="name"> <strong>Name</strong> Michael Jordan</div>
<div class="center"> <strong>Department</strong> Act Center</div>
<div class="phone"> <strong>Ext</strong> 5204</div>
</div>
<div class="sort-plate">
<div class="name"> <strong>Name</strong> Deka Junior</div>
<div class="center"> <strong>Department</strong> Act Center</div>
<div class="phone"> <strong>Ext</strong> 5204</div>
</div>
<div class="sort-plate">
<div class="name"> <strong>Name</strong> Chris Okorondu</div>
<div class="center"> <strong>Department</strong> Act Center</div>
<div class="phone"> <strong>Ext</strong> 5204</div>
</div>
<div class="sort-plate">
<div class="name"> <strong>Name</strong> Angela Jones</div>
<div class="center"> <strong>Department</strong> Act Center</div>
<div class="phone"> <strong>Ext</strong> 5204</div>
</div>
<div class="sort-plate">
<div class="name"> <strong>Name</strong> Ikechukwu Adaora</div>
<div class="center"> <strong>Department</strong> Act Center</div>
<div class="phone"> <strong>Ext</strong> 5204</div>
</div>
</div>