How would I count the number of elements with the attribute of "selected" if the **selected attribute is added dynamically on click**?

Here is how I'm adding the "selected" attribute:

```
    var $li = $('.swrt_checkbox_button');

    $li.on('click', function(){

        var $el = $(this);
        $el.toggleClass('checkbox-selected');
        $el.attr('selected', function(index, attr){
            return attr == "selected" ? null : "selected";
        });
    });

```

So, what I want to achieve is, if all my elements have the selected attr, then I want to do something, in this case, disable another UI element. 

The problem I'm having is this, if I check to see if the attr is selected within the click it works:

```
if($el.is("[selected]")) {
    console.log('yes');
}

```

This logs inside the click function but not outside it. So how can I say:

If all elements have "selected" attr { do stuff }? 

Obviously I can't do it within the click because the $el is pointing to "this". 

Any help or advice you can offer would be much appreciated. 

Thanks