Skip to content

Instantly share code, notes, and snippets.

@thinsoldier
Last active August 20, 2017 21:45
Show Gist options
  • Save thinsoldier/60d45e37bf9e66374238b6078a1097e6 to your computer and use it in GitHub Desktop.
Save thinsoldier/60d45e37bf9e66374238b6078a1097e6 to your computer and use it in GitHub Desktop.
VueJs 2 vs JQuery Comparision - jquery
<!-- https://youtu.be/HQDkXTlgY14 -->
<input type="text" class="js-filter"> Full Regular Expression Search (case insensitive)
<ul class="js-posts"></ul>
var people = ['Apple','Banana','Orange','Facebook','Twitter','Youtube'];
// Remove any items that might already exist
$('.js-posts').empty();
// Add the items to the DOM
$.each(people, function(index,person){
$('.js-posts').append("<li>"+ person +"</li>");
});
// Listen to when the input changes
$('.js-filter').on('keyup', function(){
// Get the search value
var value = $(this).val();
// Hide all posts
$('.js-posts li').hide();
// Only show the posts that match
$('.js-posts li').filter( function(){
var text = $(this).text();
return Array.isArray( text.match( new RegExp(value, 'i') ) );
}
).show();
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment