Apologies if this is a duplicate, I have searched and searched and can't figure this out.
I am using a plugin to create an accessible accordion. However, the client requirement is that it's only an accordion on small screens. This isn't a native feature of the plugin, so with my (very) limited skills I'm trying to make it happen.
This is what I've come up with:
$(function () {
if (matchMedia) {
var mq = window.matchMedia("(max-width: 500px)");
mq.addListener(WidthChange);
WidthChange(mq);
}
function WidthChange(mq) {
if (mq.matches) {
$('.js-accordion').accordion();
}
else {
$('.js-accordion').removeClass('accordion');
}
}(window.jQuery)
});
This works fine when the window resizes down; the "accordion" class is added, which calls the plugin. However, when the window resizes back up, although the class is removed, all of the HTML, ARIA, etc that the plugin adds are still there, so it doesn't convert back until the page is refreshed. I don't want to refresh the whole page, just the accordion. I tried .load and it stops the whole thing working.
Most answers to this type of question seem to involve Ajax and refreshing a piece of content from the server; I just want to refresh part of the HTML.
Pardon my ignorance, I'm sure there's an easy solution (or maybe a better way of doing it), but I am still tearing my hair out after a day of working on this. Thanks in advance!