I am trying to implement jQuery reserve for an element details. If you've never heard of this, this is basically a disclosure widget . If a logical attribute is present open, it indicates that the user will be shown both a summary and additional information. If the attribute is missing, only a summary will be displayed. The following HTML and CSS achieve this.
HTML
<details open>
<summary>Summary</summary>
<p>Additional information</p>
</details>
<details>
<summary>Summary</summary>
<p>Additional information</p>
</details>
CSS
details summary ~ * {
display: none;
}
details[open] summary ~ * {
display: block;
}
Then I added the following jQuery to add / remove an attribute openwhen an element is clicked summary.
JQuery
$("summary").click(function() {
if ($(this).parent().attr("open")) {
$(this).parent().removeAttr("open");
} else {
$(this).parent().attr("open", "open");
}
});
It adds and removes the attribute open, however the visibility of the element premains unchanged in Chrome. What am I doing wrong? Here is a living example .
Update