I have the following DOM elements:
<div id="container">
<ul class="block-grid three-up">
<li>One</li>
<li>Two</li>
<li>Three</li>
<li>Four</li>
<li>Five</li>
<li>Six</li>
</ul>
</div>
What I want to do is for the ul to have a class that states which li is being hovered over. So far, I have:
$('#container li').hover(function() {
i = $(this).index() + 1;
// need function to remove all classes that start with n- here
$('#container ul').addClass('n-'+i);
$(this).addClass('active');
}, function() {
// need function to remove all classes that start with n- here
$(this).removeClass('active');
}
);
I need to figure out a way for it to remove all classes that start with n- as well because as the code is written now, it is just adding and adding classes to the ul. I can't simply remove all other classes because there are additional classes there that I need for structural reasons. And I know that there is not a way to use a wildcard in removeClasses. Is there some kind of regular expression I can use here?