Gene9y
Gene9y

Reputation: 859

Remove a class in all nested a elements jQuery

This would be simple but I am stuck. How can I remove all hidden classes in nested a elements in the list without using a loop?

<ul class="hello">
  <li><a class="hidden">test 1</a></li>
  <li><a class="">test 2</a></li>
  <li><a class="hidden">test 3</a></li>
</ul>

So it would show test 1, test 2, test 3.

Upvotes: 1

Views: 1592

Answers (1)

Mohammad Usman
Mohammad Usman

Reputation: 39322

"without using a loop" seems your are looking for some JavaScript / jQuery solution.

You can use following code:

jQuery('.hello a').removeClass('hidden');

jQuery('.hello a').removeClass('hidden');
.hidden {
  display: none;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<ul class="hello">
  <li><a class="hidden">test 1</a></li>
  <li><a class="">test 2</a></li>
  <li><a class="hidden">test 3</a></li>
</ul>

Upvotes: 3

Related Questions