Skip to content

Instantly share code, notes, and snippets.

@dennysfredericci
Created July 22, 2014 18:19
Show Gist options
  • Star 9 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save dennysfredericci/ca99b08648649b545dfd to your computer and use it in GitHub Desktop.
Save dennysfredericci/ca99b08648649b545dfd to your computer and use it in GitHub Desktop.
A simple jquery code to search a text inside of li tag
//searchText is a input type text
$('#searchText').bind('keyup', function() {
var searchString = $(this).val();
$("ul li").each(function(index, value) {
currentName = $(value).text()
if( currentName.toUpperCase().indexOf(searchString.toUpperCase()) > -1) {
$(value).show();
} else {
$(value).hide();
}
});
});
@jagroop
Copy link

jagroop commented Jul 20, 2017

thanks for sharing 👍

@iamprakasam
Copy link

iamprakasam commented Aug 28, 2018

Thanks for the code and it works well. but we need to add var keyword in front of currentName variable.
var currentName = $(value).text()

@rahulcs754
Copy link

thanks for this

@pranav-ted
Copy link

thanks

@Awad2002
Copy link

Awad2002 commented Nov 9, 2021

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment