I've got a templated element on my site which is created with PHP. It appears on many pages of my site. Within the template is a span
with a class of hidden
. When a button
in the element is clicked, it removes the class of hidden
from the span
. It works great on the first page, but the problem is that once the class is removed from the span
it pervades across all pages with that template. Is there a way to replace the hidden class when the page is refreshed?
This is a WordPress site, and I can provide any relevant code snippets. The javascript is quite simple, just a jQuery click trigger on the button which removes the hidden class, and the page mark-up is very straightforward.
Here are Gists with the PHP template part:
https://gist.github.com/weaverhe/7d8dec4a522a12478289 (this code is simply included in the appropriate template files with PHP)
And the javascript:
Relevant Snippet:
// Show the filter bar on button click
function showFilters() {
$('#toggle-filters').on('click', function(e) {
if($('div.filters').hasClass('hidden')) {
e.preventDefault();
$('div.filters').removeClass('hidden');
$(this).removeClass('grey').text('Apply Filters');
$('#remove-filters').removeClass('hidden');
$('#chosen-tag-holder span.active').removeClass('hidden');
}
else {
return true;
}
});
}
The #chosen-tag-holder
selector which removes the hidden class is what should be resetting on the page reset.
Full Filter Bar JS: https://gist.github.com/weaverhe/05e05e45dbbcc9f10f47
The allFilters();
function is run on every page at document.ready