Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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

This comment has been minimized.

Copy link

@jagroop jagroop commented Jul 20, 2017

thanks for sharing 👍

@iamprakasam

This comment has been minimized.

Copy link

@iamprakasam 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

This comment has been minimized.

Copy link

@rahulcs754 rahulcs754 commented Jul 6, 2020

thanks for this

@pranav-ted

This comment has been minimized.

Copy link

@pranav-ted pranav-ted commented Nov 5, 2020

thanks

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