Switch classes in jQuery

Posted by Jaggi on August 24th, 2009

jQuery comes with a nice little function called toggleClass() which is good in certain cases, for example when you want to turn a class on or off. However there have been many circumstances where i wanted to swop a class with another. To get around this i wrote this function:

jQuery.fn.switchClass = function(a, b) {
	elm = $(this);
	if ( elm.hasClass(a) ) {
		elm.removeClass(a).addClass(b);
	} else {
		elm.removeClass(b).addClass(a);
	}
};

All you need to do to use it is call the function and pass in the names of the two classes. E.g:

$('a').click( function() {
	$('div').switchClass('up', 'down');
});

This will remove the class up and add the class down, when clicked again it will do the opposite therefore not needing to call it again.

Note: theres a function which can achieve this in jQuery UI however if you don’t want to load a entire new library for a simple function then use this, since they’re called the same you should use one OR the other.

IPBTracker Updates

Posted by Jaggi on April 7th, 2008

Right seems this whole blogging thing is getting on top of me and so I haven’t been making regular posts. I hope to change that but for the time being here’s some updates about the IPBTracker site.

The site has been officially relaunched however the member database has not been restored as this would cause further delays. Sorry for this but it doesn’t take long to re-register. Also I’m pleased to announce that IPBTracker 2.0 has been released and just to show how long I take to blog beta 2 has already been released.

Check out www.ipbtracker.eu news forum for downloads and hope the long wait has been worth it. Think that’s about it on the IPBTracker side of things so till next time happy editing.

Site Coming Back Soon…

Posted by Jaggi on March 11th, 2008

Will be relaunching the site complete with IPBTracker 2.0 very soon. Check out IPBTracker.eu for further information and support regarding IPBTracker past and present releases.


Copyright © 2017 CodeTheInter.net.