hasClass is useful when I want to check if the element has some class. I want to do the same check for some other attribute. For example, I use
<div id="nav" data-available-for="users administrators guests"></div>
and want to check if this div is available for users. So, I would do it like
$('#nav').hasAttributeValue('data-available-for', 'users')
Are there any existing beautiful tiny solutions for this?
There is no need to explode strings or use indexOf. jQuery has a complete set of css-selectors build in and so you can use attribute-selectors.
you can combine
.is()and attribute-selectors:http://api.jquery.com/category/selectors/
http://api.jquery.com/attribute-contains-word-selector/