My goal is to add some jQuery to a project that will check to see if an element has a data-attribute
without a value. For instance, with the video
tag you can just add autoplay
without a value and it will autoplay. I am attempting to do the same thing and wondering if it is possible. Here's what I tried, but it's returning false currently:
$(function() {
$('div').click(function() {
if ($(this).attr('data-specs')) {
console.log('has specs');
} else {
console.log('no specs');
}
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div data-specs>Specs</div>