Tag Archive for jquery

Determining State with jQuery UI Accordion

It’s quite simple really, but it’s not documented and it took me a little time to figure out, so I figured I’d share.

The basic HTML structure of the clickable portion of the accordion is:


So when you’re creating your code, the easiest way is to assign a class to the <a> element like so:

	<a class="my_accordion">...</a>

jQuery UI is nice in that it assigns different classes to the <h3> element based on its state. So then you can just use the following jQuery to determine whether or not it’s open.

if($('.my_accordion').parent('h3').hasClass('ui-state-active')) {
	// accordion is open
else {
	// accordion is closed

There’s also ‘ui-state-default’ and ‘ui-state-hover’, and probably others as well.

Easy AJAX with jQuery

I realize that there’s already a lot of tutorials like this out there, but I recently needed to show a friend how to do a unique username check for a registration form via AJAX, so figured I’d share the results as it’s easier than you might think.