Ok an have an accordion, but i am not using jQuery UI. This is my code
xHTML:
<ul>
<h2>What are your hours?</h2>
<li>Donec nec justo eget felis facilisis fermentum. Aliquam porttitor mauris sit amet orci. Aenean dignissim tesque felis.</li>
<h2>What are your hours?</h2>
<li>Donec nec justo eget felis facilisis fermentum. Aliquam porttitor mauris sit amet orci. Aenean dignissim tesque felis.</li>
<h2>What are your hours?</h2>
<li>Donec nec justo eget felis facilisis fermentum. Aliquam porttitor mauris sit amet orci. Aenean dignissim tesque felis.</li>
<h2>What are your hours?</h2>
<li>Donec nec justo eget felis facilisis fermentum. Aliquam porttitor mauris sit amet orci. Aenean dignissim tesque felis.</li>
</ul>
And jquery:
$.fn.acc = function() {
$('li').not(':first').hide();
$('h2:first').addClass('selected');
$('h2').on('click', function() {
$('.selected').removeClass('selected');
$(this).addClass('selected');
var li = $(this).next('li');
check = (li.is(':visible')) ? li.slideUp(200) : ($('li').slideUp(200))(li.slideDown(250));
});
};
// Call the function here
$(function() {
$('ul').acc();
});
The code is working, but when you click on h2 tag every time you get in the console log the following message:
Uncaught TypeError: object is not a function.
Can someone tell me what is the problem, because the code is ok and works like a charm.
Here is your code redone much simpler and with valid html
— Updated to use selected class —
http://jsfiddle.net/5HfBc/6/
html:
javascript:
css: