'Count if an element has a certain class and it's data attr contains a number

Trying to get a count of each label element that has the class "active" and it's input attr, "data-price", contains just a number/price between the ["&quot].

So, if tot element count is > 0, do something...

HTML

<ul class="elem-ul">
    <li class="elem-li">
        <label class="elem-label active">    
            <input class="elem-input" data-price="[&quot;100&quot;]" type="checkbox">
       </label>         
   </li>
    <li class="elem-li">
        <label class="elem-label active">    
            <input class="elem-input" data-price="[&quot;400&quot;]" type="checkbox">
       </label>         
   </li>
    <li class="elem-li">
        <label class="elem-label active">    
            <input class="elem-input" data-price="[&quot;&quot;]" type="checkbox">
       </label>         
   </li>
    <li class="elem-li">
        <label class="elem-label">    
            <input class="elem-input" data-price="[&quot;&quot;]" type="checkbox">
       </label>         
   </li>
</ul>

jQuery I am not sure how to get the number from the input attr

$('.elem-ul .elem-label.active').each(function(){
  var elemCt = $('input.elem-input', this).attr('data-price').length;
  if(elemCt > 0){
    //do something
  }
});


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source