Home › Forums › Product Support Forums › Ajax Search Pro for WordPress Support › Category filter styling
This topic contains 8 replies, has 2 voices, and was last updated by Ernest Marcinko 2 weeks, 3 days ago.
- AuthorPosts
- April 14, 2024 at 11:18 pm #47776
I am using Ajax Search Pro on a development website for the blog page at https://kravebranding.com/drsd/disability-rights-blog/
My client wanted the category selection to look like buttons rather than radio options, so I wrote some css to make it look the way they wanted it. However, they want to have an indication on the active selected category. because the radio is nested with the input inside of the label, I am unable to target anything by using input[type=radio]:checked. Or input[type=radio]:checked + label. do you have any way to make the categories display like I have it on the page now, but show say a dark blue background on the current selected category?
April 15, 2024 at 10:15 am #47777Hi,
I think the easiest and fastest way is to use a bit of javascript to mark the selected label. In CSS it’s not possible to target parent selectors, so I don’t think there is any other option:
jQuery(function($){ $('.asp_label').on('click', function(){ $(this).parent().find('.asp_label').removeClass('asp_label_selected'); $(this).addClass('asp_label_selected'); }); });
This will add “asp_label_selected” class to the current selection, then you can target it with CSS:
Best,.asp_label_selected { }
Ernest Marcinko
If you like my products, don't forget to rate them on codecanyon :)
April 15, 2024 at 10:12 pm #47787Thank you Ernest, I did try to add this exactly as written but it doesnt seem to be working properly. If you inspect this page you will see the function loading in the head:
https://kravebranding.com/drsd/disability-rights-blog/Did I set this up incorrectly, should the function be changed a bit? My experience with CSS is high, my JS and JQuery is very low though, so your help is appreciated!
April 15, 2024 at 10:17 pm #47788Could this be written in vanilla JS rather than jquery?
April 16, 2024 at 10:11 am #47793The header is not the best place for the script, I recommend putting it to the footer, right before the closing body tag, that should do the trick. When I initiate it from the console it does work, so the issue is only the timing.
Could this be written in vanilla JS rather than jquery?
Best,
Surely, it would be a bit more complicated, but since you have jQuery on the pages loaded, it’s just much simpler to utilize it.
Ernest Marcinko
If you like my products, don't forget to rate them on codecanyon :)
April 17, 2024 at 2:17 am #47802I moved the code to the theme file right before the closing body tag. A bunch of plugin scripts automatically insert below (a lot from ajax pro) it so that seems to be the lowest I can place it. Any suggestions?
April 17, 2024 at 12:25 pm #47812It still should be okay, maybe there is a delay on the window load and a timeout could actually fix it:
Best,jQuery(function($){ const load = () => { $('.asp_label').on('click', function(){ $(this).parent().find('.asp_label').removeClass('asp_label_selected'); $(this).addClass('asp_label_selected'); }); } load(); setTimeout(()=>load(), 1500); });
Ernest Marcinko
If you like my products, don't forget to rate them on codecanyon :)
April 17, 2024 at 4:53 pm #47826This worked! Thank you so much!
April 17, 2024 at 5:18 pm #47827You cannot access this content. Best,
Ernest Marcinko
If you like my products, don't forget to rate them on codecanyon :)
- AuthorPosts
You must be logged in to reply to this topic.