Last active
November 2, 2015 08:57
-
-
Save kshoufer/9263239 to your computer and use it in GitHub Desktop.
Ajax Live Search jQuery.
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
$('#search').keyup(function () { | |
var searchField = $('#search').val(); | |
if (searchField.length) | |
{ | |
var myExp = new RegExp(searchField, "i"); | |
var found = 0; | |
$.getJSON('data.json', function (data) { | |
var output = '<ul class="searchresults">'; | |
$.each(data, function(key, val) { | |
if (val.title.search(myExp) !== -1) { | |
console.log(val); | |
found = 1; | |
output += '<li>'; | |
output += '<h2>' + val.title + '</h2>'; | |
output += "<a href=" + val.website + ' target="_blank" >website</a>'; | |
output += '</li>'; | |
} | |
}); | |
output += '</ul>'; | |
if (found==1) { | |
$('#update').removeClass('update-hidden'); | |
$('#update').html(output); | |
} | |
else { | |
$('#update').addClass('update-hidden'); | |
} | |
}); | |
} else { | |
$('#update').addClass('update-hidden'); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment