mathiasbynens / jquery-details

World’s first <details>/<summary> polyfill™
https://mths.be/details
GNU General Public License v2.0
121 stars 34 forks source link

Toggling States Doesn't Work? #6

Closed HughxDev closed 12 years ago

HughxDev commented 12 years ago

Trying to close all other details elements when one is opened, "accordion-style". Have tried this in Chrome:

$('details').details();
$('nav li > details').on('open.details', function() {
    var details = $(this);
    details.parent().siblings().find('details').details('close');
});

as well as the same with .trigger('close.details') and triggerHandler('close.details'). Is this a bug or am I doing something wrong?

mathiasbynens commented 12 years ago

There is no such signature as .details('close') in this plugin, so that wouldn’t work.

You want to do this: https://github.com/mathiasbynens/jquery-details/blob/541097e13a251c4d652010fd3842c75886eae980/jquery.details.js#L34-46

Note that Chrome uses a native <details> implementation, so just triggering the close.details handler is not enough — you need to call .prop('open', false).

HughxDev commented 12 years ago

OK, thank you. Figured there would be a single method of invoking regardless of whether the behavior was native or polyfilled—obviously, this solution is simple enough, but I’d like to propose that feature, as a compliment to toggleOpen.