Skip to content

Instantly share code, notes, and snippets.

@dennysfredericci
Created July 22, 2014 18:19
Show Gist options
  • Select an option

  • Save dennysfredericci/ca99b08648649b545dfd to your computer and use it in GitHub Desktop.

Select an option

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

jagroop commented Jul 20, 2017

Copy link
Copy Markdown

thanks for sharing 👍

@iamprakasam

iamprakasam commented Aug 28, 2018

Copy link
Copy Markdown

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
Copy Markdown

thanks for this

@pranav-ted

Copy link
Copy Markdown

thanks

@Awad2002

Awad2002 commented Nov 9, 2021

Copy link
Copy Markdown

Thanks

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