since jQuery 1.4 removeClass(); now takes a function as argument.
My <body> tag has a few classes added to it, for example:
<body class="heading-helvetica para-georgia pattern-flowers">
I wish to be able to replace the classnames, and I believe the function in removeClass() can help me, but I don’t really understand the documentation on the jQuery site nor am I any good with Regex.
How can I replace for example heading-helvetica with heading-myriad or para-georgia with para-times and so on?
I had previously used something like this, which works only if the class name it is trying to replace is the first in the list of class names:
$('#headings li').click(function(){
var this_class = $(this).attr('id');
$('body[class|="heading"]').removeClass();
$('body').addClass(this_class);
});
You will need to get the list of classes from the
bodytag and iterate / parse them.See this article for how to get the classes.
Get class list for element with jQuery
You will have to figure out a list of classes to add and a list of classes to remove. Using a function as the parameter of the removeClass method isn’t really necessary. Since you also need to add classes, it probably is the wrong way to go.