$.search is a jQuery plugin that lets you hide or show matching elements as the user types in a search box.
In this article, you will learn how to:
Live Demo: Here’s what you will end up building:
git clone https://github.com/tejesh95/g1-search.git $('body').search()
<!DOCTYPE html>
<html>
<head>
<title>g1 search</title>
</head>
<body>
<script src="https://cdn.jsdelivr.net/combine/npm/jquery,npm/g1"></script>
<script>
$('body').search()
</script>
</body>
</html> Create a class called d-none in <style> section inside <head> tag
<!DOCTYPE html>
<html>
<head>
<title>g1 search</title>
<style>
.d-none {
display: none;
}
</style>
</head> data-hide-class="d-none" attribute to add the d-none class to all non-matching target elements.
To summarise: On <input type="search"> tag,
data-target attribute is to identify target elements. data-search attribute is to identify text content inside the target elements.data-hide-class attribute adds the class to all non-matching target elements.The final code looks like:
<!DOCTYPE html>
<html>
<head>
<title>g1 search</title>
<style>
.d-none {
display: none;
}
</style>
</head>
<body>
<input type="search" data-search="@text" data-target=".list-item" data-hide-class="d-none">
<ul>
<li class="list-item">First item text content</li>
<li class="list-item">Second item text content</li>
<li class="list-item">Third item text content</li>
</ul>
<script src="https://cdn.jsdelivr.net/combine/npm/jquery,npm/g1"></script>
<script>
$('body').search()
</script>
</body>
</html> A look into another example:
To hide elements that do not match url link attribute
To find matches based on href attribute url links, give data-search=”href”.
To read full documentation of $.search, head to https://learn.gramener.com/guide/g1/search
In part 2 of the article, we will explore how to enable search transformations on input text to do fuzzy/synonym searches.
Industry 4.0 solutions originally had their genesis in manufacturing. “The Fourth Industrial Revolution, Industry 4.0,… Read More
Improvement in production performance can enhance supply chain efficacy. There is a continuous discourse around… Read More
Sshhhhhh, ChatGPT knows everything!! In 2023, Generative AI (GenAI) emerged as a major technology disruption… Read More
Generative AI holds immense promise for healthcare, leveraging large datasets to innovate medical imaging, treatment… Read More
NJBIZ has recognized Naveen Gattu, Founder and Chief Operating Officer of Gramener—A Straive Company, as… Read More
This website uses cookies.
Leave a Comment