Basically I have a jQuery wrapped set and a date and what I want is to validate if the date does not exist on the wrapped set.
What I am trying is the following:
var selectedTourDate = $("#tourDate").val();
var isDateBooked = $("#bookedTourDate *").each(function () {
if (this.innerHTML == selectedTourDate) return true;
else return false;
});
if (isDateBooked) alert("Date invalid");
But the isDateBooked contains some sort of function:
jQuery.fn.jQuery.init[1]
How would the correct way to accomplish this be?
In your code,
isDateBookedis a jQuery object, which will always return true. You need to test the.lengthof a jQuery object to determine if there’s anything interesting inside of it.I think what you want to do is replace
.eachwith.filter, and then test the length of the resulting jQuery object: