ExternalUse
ExternalUse

Reputation: 2075

Assign function options from anonymous function results

I'm trying to assign the "collapsible" option for a JQuery accordion by determining whether the accordion container has a particular class assigned.

So <div class="accordion">....</div> should use the default, but <div class="accordion collapsible">....</div> should be collapsible. I thought I could use a function result for the option, but I'm not sure which object I need to call to get a hold of the div's "hasClass()" function.

$(document).ready(function () {
$("div.accordion").accordion(
{
    active: 0, autoHeight: false, header: "table.xxx",
    collapsible : function() { return myDivsObject.hasClass("collapsible") }()
 }
 );

It'd be great if you could help me on how to pass or access the correct object (ie the replacement for myDivsObject above) - I've tried around with this and $(this) to no avail, and also tried about 500 other variations. Any hint would be appreciated. Thanks

Upvotes: 0

Views: 65

Answers (1)

Sidharth Mudgal
Sidharth Mudgal

Reputation: 4264

Do:

$("div.accordion").each(function() {

var curAccordian = this;
$(curAccordian).accordion(
{
    active: 0, autoHeight: false, header: "table.xxx",
    collapsible : $(curAccordian).hasClass("collapsible")
 });
});

Upvotes: 1

Related Questions