Hi Guys,
I am loading Jquery and using the code below and no matter what I try I keep getting $("#accordion").accordion is not a function error in my firebug.
<script type="text/javascript"> $('#accordion > ul').accordion({ clearStyle: true, autoHeight: false }).bind("accordionchange", function(event, something, ui) { alert("hello"); console.dir(ui.newHeader); // jQuery, activated header console.log(ui.newHeader[0].id); //this has the id attribute of the header that was clicked doSomething(ui.newHeader[0].id); }); var doSomething = function(paneId) { $('#' + paneId).html('My dog\'s breath smells like dog food'); }; </script>
<div id="accordion">
<ul id="files-accordion" class="ui-accordion-container" style="padding-top: 10px; width: 550px; clear: both;">
<li><a href="#" class="ui-accordion-link">Jquery Accordion Item 1</a>
Jquery Accordion Item 1
</li>
<li><a href="#" class="ui-accordion-link">Jquery Accordion Item 2</a>
Jquery Accordion Item 2
</li>
<li><a href="#" class="ui-accordion-link">Jquery Accordion Item 3</a>
Jquery Accordion Item 3
</li>
</ul>
</div>
1 year 42 weeks ago
Did you load your Jquery javascript in document.ready? Look below:
Did you load jquery.accordion-1.2.2.js in your head after loading jquery.js:
Finally, the code below worked:
<html> <head> <link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css" rel="stylesheet" type="text/css"/> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"></script> <script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js"></script> <script type="text/javascript" src="http://jqueryui.com/latest/ui/ui.core.js"></script> <script type="text/javascript" src="http://jqueryui.com/latest/ui/ui.accordion.js"></script> <script type="text/javascript"> $(document).ready(function () { $('#accordion > ul').accordion({ clearStyle: true, autoHeight: false }).bind("accordionchange", function(event, ui) { alert(ui.newHeader[0].id); console.dir(ui.newHeader); // jQuery, activated header console.log(ui.newHeader[0].id); //this has the id attribute of the header that was clicked doSomething(ui.newHeader[0].id); }); var doSomething = function(paneId) { $('#' + paneId).html('My dog\'s breath smells like dog food'); }; }); </script> </head> <body> <div id="accordion"> <ul id="files-accordion" class="ui-accordion-container" style="padding-top: 10px; width: 550px; clear: both;"> <li><a href="#" class="ui-accordion-link">Jquery Accordion Item 1</a> Jquery Accordion Item 1 </li> <li><a href="#" class="ui-accordion-link">Jquery Accordion Item 2</a> Jquery Accordion Item 2 </li> <li><a href="#" class="ui-accordion-link">Jquery Accordion Item 3</a> Jquery Accordion Item 3 </li> </ul> </div> </body> </html>Post Comment