Filtering with jQuery using data attributes
How do I make an filtering with jquery using data attributes?
Create a filter function with jQuery and data attributes. - Created by nickycdk. What is a filtering with jquery using data attributes? How do you make a filtering with jquery using data attributes? This script and codes were developed by Nicky Christensen on 29 September 2022, Thursday.
Filtering with jQuery using data attributes - Script Codes HTML Codes
<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>Filtering with jQuery using data attributes</title> <link rel="stylesheet" href="css/style.css">
</head>
<body> <h2>Sort News</h2>
<select name="sort-news" id="sort-news"> <option value="All">All news</option> <option value="Cat1">Category 1</option> <option value="Cat2">Category 2</option> <option value="Cat3">Category 3</option>
</select>
<hr />
<section class="news-list"> <article class="news-item" data-category="Cat1"> <div class="thumb"> <img alt="Our ALT text here" title="Our title here" src="http://placehold.it/150x150"> </div> <div class="news-txt"> <h3><a href="">A news title</a></h3> <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua...</p> </div>
</article>
<article class="news-item" data-category="Cat2"> <div class="thumb"> <img alt="Our ALT text here" title="Our title here" src="http://placehold.it/150x150"> </div> <div class="news-txt"> <h3><a href="">A news title</a></h3> <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua...</p> </div>
</article>
<article class="news-item" data-category="Cat3"> <div class="thumb"> <img alt="Our ALT text here" title="Our title here" src="http://placehold.it/150x150"> </div> <div class="news-txt"> <h3><a href="">A news title</a></h3> <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua...</p> </div> </article> </section> <script src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/t-12/jquery-2.0.3.min_1.js"></script> <script src='http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js'></script> <script src="js/index.js"></script>
</body>
</html>
Filtering with jQuery using data attributes - Script Codes CSS Codes
body { font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
}
.news-item { display:inline-block; vertical-align:top; width:300px;}
Filtering with jQuery using data attributes - Script Codes JS Codes
//Filter News
$('select#sort-news').change(function() { var filter = $(this).val() filterList(filter);
});
//News filter function
function filterList(value) { var list = $(".news-list .news-item"); $(list).fadeOut("fast"); if (value == "All") { $(".news-list").find("article").each(function (i) { $(this).delay(200).slideDown("fast"); }); } else { //Notice this *=" <- This means that if the data-category contains multiple options, it will find them //Ex: data-category="Cat1, Cat2" $(".news-list").find("article[data-category*=" + value + "]").each(function (i) { $(this).delay(200).slideDown("fast"); }); }
}
Developer | Nicky Christensen |
Username | NickyCDK |
Uploaded | September 29, 2022 |
Rating | 3.5 |
Size | 2,359 Kb |
Views | 18,216 |
Find the perfect freelance services for your business! Fiverr's mission is to change how the world works together. Fiverr connects businesses with freelancers offering digital services in 500+ categories. Find Developer!
Name | Size |
CSS3 Snow Animation | 1,695 Kb |
Greyscale image with filter in CSS3 | 1,562 Kb |
CSS3 Loading Animation | 2,140 Kb |
EqualHeight jQuery Plugin | 2,596 Kb |
TweenMax scale and rotate animation | 2,288 Kb |
Slick Slider Custom Navigation | 2,601 Kb |
CSS Animated Tooltip | 3,043 Kb |
Animated Navigation with Tweenmax, Sliding Effect | 3,567 Kb |
Open Door Effect | 1,516 Kb |
Chart JS example with gradient | 1,967 Kb |
Jasper is the AI Content Generator that helps you and your team break through creative blocks to create amazing, original content 10X faster. Discover all the ways the Jasper AI Content Platform can help streamline your creative workflows. Start For Free!
Name | Username | Size |
Simple Weather App | Cmwebby | 0 Kb |
Nav Test -- cats 1 | Payls | 4,735 Kb |
TimelineMax Circular loader | Nicolund | 2,649 Kb |
CSS Grid Overlay | Cliffpyles | 3,090 Kb |
Wikipedia Viewer | Thomasvaeth | 2,549 Kb |
FCC - Tribute Page | Cmwebby | 0 Kb |
Basic jQuery Filter list | Mtedwards | 2,464 Kb |
TweenMax transformOrigin Bubble | Nicolund | 2,209 Kb |
Spinners using Font Icons | Keyamoon | 3,007 Kb |
Amazing CSS Menu with Notification Badges | Faizanasad | 2,549 Kb |
Surf anonymously, prevent hackers from acquiring your IP address, send anonymous email, and encrypt your Internet connection. High speed, ultra secure, and easy to use. Instant setup. Hide Your IP Now!