I am trying to create a somewhat dynamic html class that sets a width % based on a number included at the end of a class. Note: Class name will always start with "gallery-item-"
Example: div.gallery-item-20 = 20% width
What I need:
Get the class name(s) and convert each to string in order to be able to read the number at the end (if this step is even necessary)
Translate that number into a % that applies to the width of each class with that name.
One might ask, why not just make separate classes? I would prefer a bit more control, that's all. Thank you in advance for any and all answers. Here is my current current code (I am fairly new to js):
$('.hollow-gallery-04').masonry({
// options
itemSelector: '.gallery-item'
});
var galleryItem = $('[class^="gallery-item-"]');
Object.values(galleryItem).forEach(function(item) {
this.toString();
console.log(galleryItem);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="hollow-gallery-04">
<div class="gallery-item-20">
<img src="http://via.placeholder.com/350x150" alt="">
</div>
<div class="gallery-item-20">
<img src="http://via.placeholder.com/500x300" alt="">
</div>
</div>