After referencing the answer to another question, I managed to write code that preserves the style when a link is activated using "data-target". However, the style disappears when navigating to the next page from the active link. For instance, if the original link is "link/sub01.html" but changes to "link/sub01.html&page=2", the style gets lost. I am looking for a solution to maintain the style whenever there is a "data-target" value in the link. Unfortunately, I am not well-versed with scripts and don't know where to make the necessary adjustments. Any assistance would be greatly appreciated.
Please excuse any language discrepancies as I used a translator for this message. Thank you for your understanding!
$(document).ready(function() {
var url = window.location;
$('.mainCateBox li a[href="' + 'data-target' + '"]').parent().addClass('active');
$('.mainCateBox li a').filter(function() {
return this.href == url;
}).parent().addClass('active').parent().parent().addClass('active');
});
- MAIN
- SUB01
- SUB02