I am trying to create a dropdown accordion box that when clicked toggles between a "+" and a "-". I got this to work with one box. But I would like to have a box within a box. For some reason the "+" and "-" does not work for all the boxes only the first one. It will change to a "-" when clicked but does not change back to a "+" when clicked again. I am assuming I need some sort of each function but I cannot figure out where to put it.
You can see an example of this at https://codepen.io/rebeccagracedesigns/pen/GRrGvGK
This is the HTML
<div class="dropdown">
<h2 class="question">This is a question.</h2>
<div class="drop-down-contents">
<div class="dropdown">
<h3 class="question">This is a question.</h3>
<div class="drop-down-contents">
<div class="dropdown">
<h4 class="question">This is a question.</h4>
<div class="drop-down-contents">
<p>This is a paragraph.</p>
</div>
</div>
<div class="dropdown">
<h4 class="question">This is a question.</h4>
<div class="drop-down-contents">
<p>This is a paragraph.</p>
</div>
</div>
<div class="dropdown">
<h4 class="question">This is a question.</h4>
<div class="drop-down-contents">
<p>This is a paragraph.</p>
</div>
</div>
</div>
</div>
<div class="dropdown">
<h3 class="question">This is a question.</h3>
<div class="drop-down-contents">
<p>This is a paragraph.</p>
</div>
</div>
</div>
</div>
This is the JQuery
$(".question").attr("dropdown-arrow", "+");
$(".question").click(function() {
$(this)
.nextUntil(".question")
.slideToggle("slow", function () {
if ($(".drop-down-contents").is(":visible")) {
$(this).siblings(".question").attr("dropdown-arrow", "-");
} else {
$(".question").attr("dropdown-arrow", "+");
}
});
});