Get all classes with the string partial name

Please, try this:

const list = []
$('[class]').each(function() {
  this.classList.forEach(function(className) {
    if (!className.indexOf('page-index-')) {
      list.push(className)
    }
  })
})
console.log(list) //list contains generated class
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="page-index-1"></div>
<div class="page-in"></div>
<div class="page-index-2"></div>
<div class="page-index-3"></div>

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top