Jump to content
EduGeek EdSec 2026 is Go! 27th Oct in Derby! Join us for a day of EdTech security focused talks, networking, and an evening social ×

Recommended Posts

Posted

I've put this together from various snippets from the web:

 

$(function() {
$('.accordian li:odd:gt(0)').hide();
$('.accordian li:first').css("background-image", "url(customnav_selected.png)"); 
$('.accordian li:even:even').addClass('even');
$('.accordian li:even:odd').addClass('odd');
$('.accordian li:even').css('cursor', 'pointer');
$('.accordian li:even').click( function() {
	var cur = $(this).next();
	var old = $('.accordian li:odd:visible');
	if ( cur.is(':visible') )
		return false;
	old.slideToggle(500);
	cur.stop().slideToggle(500);
	$(this).css("background-image", "url(customnav_selected.png)"); 
	old.prev().css("background-image", "url(customnav_available.png)"); 
} );
});

 

HTML

 


School

School Information
School Contact


Staff

Staffroom


 

Jquery 1.2.3

 

Its currently opens the first even

  • being School, what I want to be able to do is specifiy the
  • to open rather than it being based on if the list element is odd or even.

     

    Can anyone give me any pointers?

  • Posted (edited)

    Are you using this for a menu? At the risk of sounding silly, do you really want an accordion?

     

    This isn't a function I've ever used, but I've always found the jQuery documentation to be really good. I'm sure you've probably already used it, but there is a lovely example whose source you could copy and modify if you definitely want this effect: UI/API/1.7.2/Accordion - jQuery JavaScript Library

     

    It looks as though you can use the "activate" method to open a specific content item.

    Edited by NotSoFast

    Create an account or sign in to comment

    You need to be a member in order to leave a comment

    Create an account

    Sign up for a new account in our community. It's easy!

    Register a new account

    Sign in

    Already have an account? Sign in here.

    Sign In Now



    ×
    ×
    • Create New...