I want to add a class hidden
to all li
, but not to the li
that was clicked. How can I do this using jQuery?
jQuery(".render-menu li").on('click', function() {
alert();
jQuery(".render-menu").not($(this)).parent().addClass('hidden');
});
.hidden {
display: none;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><ulclass="render-menu">
<li class="font-size">list 1</li>
<li class="font-size">list 2</li>
<li class="font-size">list 3</li>
<li class="font-size">list 4</li>
</ul>