A Pen by thinsoldier on CodePen.
Last active
August 20, 2017 21:45
-
-
Save thinsoldier/60d45e37bf9e66374238b6078a1097e6 to your computer and use it in GitHub Desktop.
VueJs 2 vs JQuery Comparision - jquery
This file contains hidden or 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
<!-- https://youtu.be/HQDkXTlgY14 --> | |
<input type="text" class="js-filter"> Full Regular Expression Search (case insensitive) | |
<ul class="js-posts"></ul> |
This file contains hidden or 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
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(); | |
}); |
This file contains hidden or 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 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