I have a list with header and toggle. Currently when the ul
being toggled on, the style is display: block
; when being toggled off, the style is display: none
. Here is a snippet:
function toggle () {
var toggleClosed = $(".toggle-closed");
var toggleOpened = $(".toggle-opened");
if (!$(toggleClosed).is(":visible")) {
$(toggleClosed).show();
$(toggleOpened).hide();
} else {
$(toggleClosed).hide();
$(toggleOpened).show();
}
}
.form-row-filter {
background-color: grey;
}
.toggle-opened {
cursor: pointer;
display: block;
}
.toggle-closed {
cursor: pointer;
display: none;
}
.material-icons {
margin-right: -4px;
margin-left: 4px;
vertical-align: middle;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div>
<div class="material-icons toggle-opened" onclick="toggle()">► Companies</div>
<div class="material-icons toggle-closed" onclick="toggle()">▼ Companies</div>
<ul class="form-row-filter toggle-closed">
<li>
company a
</li>
<li>
company b
</li>
</ul>
</div>
How can I do this: when ul
being toggled off, style is still display: none
; but when toggled on, make the style of ul
be display: inline-block
? Notice I do NOT want to change the Javascript, cause I don't want to break stuff elsewhere by changing every toggle-on to display: inline-block
.
EDIT: the toggle-closed
class should be applied on the ul
element, rather than the li
element. I've modified the snippet to correct this.