Unverified

Name

Hide-Child-Taxonomy-Until-Parent-Clicked

Language

HTML

Rating

Voted: 1 by 1 user(s)

Codevault

WebSquadron

Scroll down to see more snippets from this codevault.

Wordpress Compatability

The author has indicated that this snippet is compatable up to wordpress version: 6.4

Code Snippet Plugin Sync

Free & Pro

Download this snippet by clicking the download button, then head over to the Code Snippet Plugin settings in your wordpress admin dashboard, select the import menu then upload this file to import into your wordpress site.

Pro Only (Coming Soon)

You will be able to click a button and sync this snippet to your wordpress site automatically and from your dashboard manage all code snippets across all your wordpress sites that have the Code Snippets Pro plugin installed.

History

Last modified:

03/09/2024

Important Note

This snippet has the following status:

Unverified

This snippet has not been verified, use with caution and at your own risk. See details provided by author in sidebar and click below to find out more.

Hide-Child-Taxonomy-Until-Parent-Clicked

 
                    
1<script>
2 (function($) {
3 // TaxonomyFilter Object
4 var TaxonomyFilter = {
5 toggleChildrenVisibility: function(parentSlug) {
6 // Hide all child filters first
7 $('.e-filter-item[data-filter^="child-"]').removeClass('force-show').hide();
8 
9 // Log the parentSlug for debugging
10 console.log("Parent Slug:", parentSlug);
11 
12 // Show only the children of the selected parent
13 var children = $('.e-filter-item[data-filter^="child-' + parentSlug + '"]');
14 
15 // Log each child element found
16 children.each(function() {
17 console.log("Child Filter Found:", $(this).attr('data-filter'));
18 });
19 
20 if (children.length > 0) {
21 children.addClass('force-show').show();
22 console.log("Children to Show:", children);
23 } else {
24 console.log("No children found for parentSlug:", parentSlug);
25 }
26 }
27 };
28 
29 // Filter the loop grid
30 function filterLoopGrid(filter) {
31 $('.elementor-loop-container .elementor-grid-item').hide();
32 if (filter === 'all') {
33 $('.elementor-loop-container .elementor-grid-item').show();
34 } else if (filter.startsWith('child-')) {
35 $('.elementor-loop-container .elementor-grid-item[data-category="' + filter + '"]').show();
36 } else {
37 $('.elementor-loop-container .elementor-grid-item').filter(function() {
38 var itemCategory = $(this).attr('data-category');
39 return itemCategory === filter || itemCategory.startsWith('child-' + filter.split('-')[1]);
40 }).show();
41 }
42 }
43 
44 // Hides all child elements by default
45 $(document).ready(function() {
46 $('.e-filter-item[data-filter^="child-"]').hide();
47 
48 $('.e-filter-item').on('click', function() {
49 var selectedFilter = $(this).attr('data-filter');
50 console.log("Selected Filter:", selectedFilter); // Debugging: Check which filter is clicked
51 
52 if (!selectedFilter.startsWith('child-')) {
53 // Hide all children and then show relevant ones
54 var parentSlug = selectedFilter.split('-')[1]; // Extract the slug part of the parent
55 console.log("Extracted Parent Slug:", parentSlug); // Log the extracted parent slug
56 TaxonomyFilter.toggleChildrenVisibility(parentSlug);
57 }
58 
59 filterLoopGrid(selectedFilter);
60 });
61 });
62})(jQuery);
63</script>

1

Related Snippets

Please see some snippets below related to this snippet..

Elementor

AI Verified

0

Render ACF Pro Repeater Field as shortcode in Elementor

Added: 1 year ago

Last Updated: 1 year ago

Renders the Contents of an ACF Pro Repeater field as an HTML table using a simple shortcode.

Elementor

AI Verified

0

Elementor author posts with UAE Posts widget

Added: 2 years ago

Last Updated: 1 year ago

Display posts of only the current author archive using Elementor and "Unlimited Addons for Elementor" Posts widget

Elementor

Unverified

0

Accordion Closed by Default

Added: 1 year ago

Last Updated: 1 year ago

Forces Elementor accordion to be closed by default, instead of the first one being open.

Other Snippets in this Codevault

These are some popular snippets from this users codevault..

Performance

AI Verified

35

Remove Unused Javascript

Added: 2 years ago

Last Updated: 1 week ago

Remove Unused Javascript - and improve your Page Speed Insight Score

WooCommerce

Pro Verified

10

Deactivate some WooCommerce Checkout Fields

Added: 2 years ago

Last Updated: 2 months ago

Deactivate some WooCommerce Checkout Fields from showing

Elementor

AI Verified

6

CSS Grid Aid

Added: 9 months ago

Last Updated: 3 months ago

This can be used for any WordPress Builder to aid working with CSS Grids.