I want to have an alert if the input has a class of "saninput" and the value is not equal to "".
The code works for the first example but not any others. Does anybody know how to make it so all relevant inputs create an alert?
$(document).ready(function() {
if ($(".saninput").val() != "") {
var animal = $(".saninput").data("animal");
alert(animal)
};
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input id="sheepid" data-animal="sheep" class="saninput" type="text" value="sheep">
<input id="cowid" data-animal="cow" class="saninput" type="text" value="cow">
<input id="dogid" data-animal="dog" class="saninput" type="text" value="dog">
Thanks in advance