I'm trying to implement jQuery UI accordion to collapse my fields when clicked. But it isn't working. Can someone point me in the right direction please?
$(function() {
$( "#accordion" ).accordion({
collapsible: true
});
});
I'm trying to implement jQuery UI accordion to collapse my fields when clicked. But it isn't working. Can someone point me in the right direction please?
$(function() {
$( "#accordion" ).accordion({
collapsible: true
});
});
I didn't catch that the last time, you have a $(document).ready()
and you have a $(function()
inside the $(document).ready()
, they are the same but abbreviated:
$(document).ready(function() VS $(function(){
And because you are creating the accordion after the elements are created with javascript, you need to call the accordion method because it's new content.
$.ajax({
type:"GET",
url:apiURL,
dataType:"json",
async:false,
success: function(response){
console.log(response);
searchTitles=response[1];
searchDescription=response[2];
searchLink=response[3];
for (var i = 0; i<searchTitles.length; i++) {
$(".results").prepend("<h3>"+searchTitles[i] +"</h3>" + "<div> <p>"+searchDescription[i]+"</p>" + "<a target='blank' class='btn btn-warning' href='"+searchLink[i]+"'>More</a></div>");
}
//After the new content, generate the accordion
$( "#accordion" ).accordion({
collapsible: true
});
}
});