Background: I am using ShuffleJS and when no results are returned on a filter, I want to display a message.
So I'm trying to loop through HTML generated by php and create an array of class names from children elements of a div. Then use 'inArray' to determine if any elements have the 'shuffle-item--visible'. If they don't, then print the message.
Here is my HTML example:
<div class="col-xl-2 col-lg-3 col-md-4 col-sm-6 col-xs-12 project-row shuffle-box shuffle-item shuffle-item--visible" data-order="0" data-categories="[[sef]]" data-tags="" style="position: absolute; top: 0px; left: 0px; visibility: visible; will-change: transform; opacity: 1; transform: translate(379px, 0px) scale(1); transition-duration: 250ms, 250ms; transition-timing-function: ease, ease; transition-property: transform, opacity;">
<a class="rwp-site" href="http://research.qut.edu.au/digital-agriculture">
<figure class="project-box" style="background-image: url("http://127.0.0.1/wp-content/uploads/sites/3/2016/05/57143cf93c44d8d51d2a5b9d-800x800.jpg"); min-height: 360px;">
<figcaption>
<div class="site-title">
<p>Digital Agriculture</p>
</div>
</figcaption>
</figure>
</a>
and example that is set to hidden:
<div class="col-xl-2 col-lg-3 col-md-4 col-sm-6 col-xs-12 project-row shuffle-box shuffle-item shuffle-item--visible" data-order="0" data-categories="[[cif]]" data-tags="" style="position: absolute; top: 0px; left: 0px; visibility: visible; will-change: transform; opacity: 1; transform: translate(759px, 0px) scale(1); transition-duration: 250ms, 250ms; transition-timing-function: ease, ease; transition-property: transform, opacity;">
<a class="rwp-site" href="http://127.0.0.1/dmrc">
<figure class="project-box" style="background-image: url("http://127.0.0.1/wp-content/uploads/sites/5/2017/03/DMRC_2017_group-1-800x800.jpg"); min-height: 360px;">
<figcaption>
<div class="site-title">
<p>Digital Media Research Centre</p>
</div>
</figcaption>
</figure>
</a>
</div>
It's evident that what hides/shows the element is the shuffle-item--visible/shuffle-item--hidden class.
I am using this bit of JS to try and create the array:
var sitesArray = new Array();
jQuery(".shuffle-item").each(function () {
var siteStatus = jQuery(this).find('.shuffle-item--visible').map(function () {
return this.value;
}).get();
array.push(siteStatus)
})
console.log(sitesArray);
It's very messy and not returning anything like what I am looking for E.g. ["shuffle-item--hidden", "shuffle-item--hidden", "shuffle-item--visible"...]
Firstly, what am I doing wrong? and is there a better more simplified way of achieving the result? To determine if a jsshuffle category/filter pulls back null results?
<div>has no value