Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

check if jquery ui accordion exists?

is there an easy way to tell if a jquery accordion exists on the page...i am trying to dynamically build accordion based on selection that runs through $ajax, reads values from xml, and depending on the xml file selected builds strings the make up the accordion, and finally appends it.

I think that if the accordion already exists on the page, and the user selects another file, I am having trouble destroying the accordion, clearing the html, append the new string, then creating a new accordion...

like

$("#accordion").accordion('destory').html('').append(string).accordion();

seems like if there is not already an accordion this idea breaks....thinking maybe i can just check?? thanks for any help to beginner!

like image 318
Justin Avatar asked Jan 21 '13 19:01

Justin


1 Answers

I suspect that you could try checking .data().

var isAccordion = !!$("#accordion").data("ui-accordion");

Or, by checking the ui-accordion classname using .hasClass() which is added upon initialization.

var isAccordion = $("#accordion").hasClass("ui-accordion");
like image 133
Alexander Avatar answered Sep 18 '22 23:09

Alexander